elasticsearch _script 脚本排序
具体脚本语法请自行搜索“Groovy”语法。
{
"from" : 0,
"size" : 5,
"query" : {
"bool" : {
"filter" : {
"terms" : {
"id" : [ "33009", "30025", "20281", "16221", "103859", "102738" ]
}
}
}
},
"sort" : [ {
"_script" : {
"script" : {
"inline" : "def boolean bo1 = false;def boolean bo2 = false;def zhenghoumc = doc['binganList.zhenghoumc.raw'];def yongyao=doc['binganList.zhenciList.zhongyaozlList.zhongyaozcList.danweiymc.raw'];for(i in 0..<yongyao.size()){if(yongyao[i]!=''){bo1=true;break}};for(i in 0..<zhenghoumc.size()){if(zhenghoumc[i]!=''){bo2=true;break}};bo2==false&&bo1==false?0:(bo2==false&&bo1==true?1:(bo1==true&&bo2==true?10:9))"
},
"type" : "number",
"order" : "desc"
}
} ]
}
boolQuery.filter(QueryBuilders.termsQuery("id", list));
SearchRequestBuilder builder = this.client.prepareSearch("cmhealth1");
builder.setTypes("docase");
builder.setQuery(boolQuery);
// SortBuilder aa = SortBuilders.fieldSort("yongyao").;
// Script aa = new ScriptSortBuilder("''==doc['source'].value?0:1","number").order(SortOrder.ASC);
Script script=new Script("def boolean bo1 = false;def boolean bo2 = false;"
+ "def zhenghoumc = doc['binganList.zhenghoumc.raw'];"
+ "def yongyao=doc['binganList.zhenciList.zhongyaozlList.zhongyaozcList.danweiymc.raw'];"
+ "for(i in 0..<yongyao.size()){if(yongyao[i]!=''){bo1=true;break}};"
+ "for(i in 0..<zhenghoumc.size()){if(zhenghoumc[i]!=''){bo2=true;break}};"
+ "bo2==false&&bo1==false?0:(bo2==false&&bo1==true?1:(bo1==true&&bo2==true?10:9))");
ScriptSortBuilder scriptSortBuilder = SortBuilders.scriptSort(script, "number").order(SortOrder.DESC);
// builder.addSort("binganList.zhenghoumc", SortOrder.DESC);
builder.addSort(scriptSortBuilder);
builder.setFrom(pageNum);
builder.setSize(pageSize);
SearchResponse response = builder.get();
elasticsearch _script 脚本排序的更多相关文章
- elasticsearch开启脚本及使用
开启script: Scripting settingsedit The script.disable_dynamic node setting has been replaced by fine-g ...
- Elasticsearch高级搜索排序( 中文+拼音+首字母+简繁转换+特殊符号过滤)
一.先摆需求: 1.中文搜索.英文搜索.中英混搜 如:"南京东路","cafe 南京东路店" 2.全拼搜索.首字母搜索.中文+全拼.中文+首字母混搜 如 ...
- Elasticsearch 实现自定义排序插件
插件入口: package ttd.ugc.plugin; import org.elasticsearch.plugins.Plugin;import org.elasticsearch.scrip ...
- 删除elasticsearch索引脚本
只保留七天的索引 shell版 #!/bin/bash #hexm@ #只保留一周es日志 logName=( -nginxaccesslog -nginxerrorlog -phperrorlog ...
- ElasticSearch中设置排序Java
有用的链接:http://stackoverflow.com/questions/12215380/sorting-on-several-fields-in-elasticsearch 有的时候,需要 ...
- elasticsearch 权威指南排序阅读笔记(六)
默认排序 默认查询是通过_source 准确性权重来排序 字段排序 { "query":{ "match":{ "productName": ...
- elasticsearch备份脚本
1.主要文件 [root@k8s elasticsearch]# tree . ├── backup_es.sh ├── indices_file.txt ├── recover_es.sh └── ...
- elasticsearch painless脚本评分
painless是一种新支持的脚本语言,语言格式和java十分类似.可以参考以下文档: painless语言介绍 painless api painless 实例 脚本参数 score_mode计算f ...
- ElasticSearch(7)-排序
引用自ElaticSearch权威指南 一.排序 相关性排序 默认情况下,结果集会按照相关性进行排序 -- 相关性越高,排名越靠前. 这一章我们会讲述相关性是什么以及它是如何计算的. 在此之前,我们先 ...
随机推荐
- LINUX内核完全注释
学习教材:LINUX内核完全注释,内核版本0.11,修正版V3.0 赵炯编著 参考教材:UNIX操作系统设计--M. J. Bach, programming the 80x86 --John H. ...
- ISO-8859-1和GBK互转
String slogn = "极简主义"; byte[] bytes = slogn.getBytes("GBK");// 编码:字符串变成字节数组 输入 参 ...
- 2.7 多窗口、句柄(handle)
2.7 多窗口.句柄(handle) 前言 有些页面的链接打开后,会重新打开一个窗口,对于这种情况,想在新页面上操作,就得先切换窗口了.获取窗口的唯一标识用句柄表示,所以只需要切换句柄,我们就能在 ...
- 2017-2018-2 20165228 实验二《Java面向对象程序设计》实验报告
2017-2018-2 20165228 实验二<Java面向对象程序设计>实验报告 相关知识点 三种代码 伪代码:注释,与具体编程语言无关 产品代码:由伪代码翻译而来的具体编程语言语法相 ...
- [LeetCode&Python] Problem 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- Unity 3D接入ShareSDK流程2
Unity开发VR之Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- P3084 [USACO13OPEN]照片Photo (dp+单调队列优化)
题目链接:传送门 题目: 题目描述 Farmer John has decided to assemble a panoramic photo of a lineup of his N cows ( ...
- (24)ajax上传json格式的数据
urs.py from django.conf.urls import urlfrom django.contrib import adminfrom app01 import viewsurlpat ...
- html和vue框架
HTML写的页面,每次跳转的时候都要向服务器请求 vue框架:单页面运用,路由的跳转,方便
- curl提示不支持https协议解决方法
根据网上的资料,这个问题的原因是因为在安装curl时使用默认安装,但是默认安装并不支持https协议 简单粗暴的办法就是,卸载重新安装curl(有一种方法是重新编译就可以了,然后使用编译后的可执行文件 ...