org.elasticsearch.script.Script使用
org.elasticsearch.script.Script使用
public Map<String, Object> builderMapPackage(PageBean pageBean, QueryBuilder queryBuilder, String esIndex, String esType,
Map<String, String> sortsMap, Map<String, String> scriptsMap, Map<String, Map<String, Object>> scriptsParams){
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
// painless脚本排序
if (CommonFuctions.isNotEmptyMap(scriptsMap)) {
// 必发sort
if(scriptsMap.containsKey("taskList")){
Script sc = new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, scriptsMap.get("taskList"),
scriptsParams.get("taskList"));
searchSourceBuilder.sort(new ScriptSortBuilder(sc, ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.ASC));
}
// 置顶过期时间sort
if (scriptsMap.containsKey("topExpiredDate")) {
Script sc = new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, scriptsMap.get("topExpiredDate"),
scriptsParams.get("topExpiredDate"));
searchSourceBuilder.sort(new ScriptSortBuilder(sc, ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.ASC));
}
}
// 普通排序
if(CommonFuctions.isNotEmptyMap(sortsMap)){
for(String sort : sortsMap.keySet()){
if(sortsMap.get(sort).equals("asc")){
searchSourceBuilder.sort(sort, SortOrder.ASC);
}else{
searchSourceBuilder.sort(sort, SortOrder.DESC);
}
}
}
// 分页
if(pageBean != null){
searchSourceBuilder.from(pageBean.getStartIndex());
searchSourceBuilder.size(pageBean.getPageSize());
}
// 创建查询索引,参数esIndex表示要查询的索引库为esIndex
Map<String, Object> builderMap = new HashMap<>();
builderMap.put("builderString", searchSourceBuilder.toString());
builderMap.put("esIndex", esIndex);
builderMap.put("esType", esType);
return builderMap;
}
@Override
public QueryBuilder productBuilder(EsListDto esListDto, String searchKey, String dateString, String regex, boolean isNewRedPackage){
Long currentTime = System.currentTimeMillis();
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
//用于关键字查询
if(null != searchKey){
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//模糊匹配,主要用于字母的相关查询
boolQuery.should(QueryBuilders.wildcardQuery("productName","" + searchKey + ""));
boolQuery.should(QueryBuilders.wildcardQuery("sellingPoints","" + searchKey + ""));
boolQuery.should(QueryBuilders.wildcardQuery("productItem","" + searchKey + ""));
queryBuilder.must(boolQuery);
}
//用于产品名称查询
if(null != esListDto.getProductList()){
BoolQueryBuilder contentBoolQuery = QueryBuilders.boolQuery();
esListDto.getProductList().forEach(i -> contentBoolQuery.should(QueryBuilders.wildcardQuery("productName","" + i + "")));
queryBuilder.must(contentBoolQuery);
}
//用于内容标签查询
if(null != esListDto.getContentList()){
BoolQueryBuilder contentBoolQuery = QueryBuilders.boolQuery();
esListDto.getContentList().forEach(i -> contentBoolQuery.should(QueryBuilders.wildcardQuery("productItem","" + i + "")));
queryBuilder.must(contentBoolQuery);
}
queryBuilder.must(QueryBuilders.boolQuery().should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("isShow")))
.should(QueryBuilders.termQuery("isShow", "Y")))
.must(QueryBuilders.boolQuery().should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("status")))
.should(QueryBuilders.termQuery("status", "2")).should(QueryBuilders.termQuery("status", "4")))
.must(QueryBuilders.boolQuery().should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("endDate"))).should(QueryBuilders.rangeQuery("endDate").gt(dateString)))
.must(QueryBuilders.boolQuery().should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("startDate"))).should(QueryBuilders.rangeQuery("startDate").lt(dateString)))
//存在分批上架功能,需要判断codeList和whiteList,不存在分批上架功能,需要判断whiteList,publishBranchList,thirdRegionCodes
.must(QueryBuilders.boolQuery()
.should(QueryBuilders.boolQuery().must(QueryBuilders.nestedQuery("codeList", QueryBuilders.boolQuery().must(QueryBuilders.regexpQuery("codeList.branch", regex))
.must(QueryBuilders.boolQuery()
.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("codeList.endDate")))
.should(QueryBuilders.rangeQuery("codeList.endDate").gt(currentTime)))
.must(QueryBuilders.rangeQuery("codeList.startDate").lt(currentTime)), ScoreMode.None))
.must(QueryBuilders.boolQuery()
.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("whiteList")))
.should(QueryBuilders.matchQuery("whiteList", esListDto.getAgentNo()))))
.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.nestedQuery("codeList", QueryBuilders.existsQuery("codeList.branch"), ScoreMode.None)).must(QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("whiteList", esListDto.getAgentNo()))
.should(QueryBuilders.boolQuery()
.mustNot(QueryBuilders.existsQuery("whiteList"))
.must(QueryBuilders.boolQuery()
.should(QueryBuilders.regexpQuery("publishBranchList", regex))
.should(QueryBuilders.regexpQuery("thirdRegionCodes", regexForEs("",esListDto.getRegionCode())))))))
)
;
//需要过滤老版本中的红包产品
if(!isNewRedPackage){
queryBuilder.mustNot(QueryBuilders.termQuery("productType", "ZX"));
}
return queryBuilder;
}
org.elasticsearch.script.Script使用的更多相关文章
- Elasticsearch Painless script编程
我们之前看见了在Elasticsearch里的ingest node里,我们可以通过以下processor的处理帮我们处理我们的一些数据.它们的功能是非常具体而明确的.那么在Elasticsearch ...
- xss实例-输出在<script></script>之间的情况
1. 我们找到这么一个点,也是输入和输出都未过滤的一个点.相比教程第一例,其特殊之处在于,是输出在了 <script>[输出]</script>之间. http://activ ...
- 哪种写法更好?<script></script> vs/or <script type=”text/javasript”></script>
一直很奇怪 哪种写法更好<script type=“text/javascript”>…</script> or <script>…</script>? ...
- <script>, <script async>, <script defer> 三种标签的区别
<script>, <script async>, <script defer> 三种标签的区别 <script>标签 阻塞html parsing 脚 ...
- Vue <script></script>区域使用filter过滤器
Vue中过滤器(filter)的功能高度提取,便于使用,前端小伙伴们使用的频率很高.但大多数都是在模板区域来使用. 如果要在脚本区域, 也就是来使用已经定义好过滤器功能,该如何去做呢? 难道需要在ut ...
- elasticSearch script api
Package org.elasticsearch.script Support for running user provided scripts (in the request, in clust ...
- 页面中多个script块之间的关系
一:函数声明与函数定义表达式在函数调用间的区别 <script type="text/javascript"> doA(); var doA = function(a ...
- javaScript中的小细节-script标签中的预解析
首先介绍预解析,虽然预解析字面意思很好理解,但是却是出坑出的最多的地方,也是bug经常会有的地方,利用好预解析的特性可以解决很多问题,并且提高代码的质量及数量,浏览器在解析代码前会把变量的声明和函数( ...
- JS中script词法分析
核心:JS中的script是分段执行的. <script> var i = 10; </script> <script> alert(i); </script ...
随机推荐
- Error creating bean with name 'us' defined in class path resource [com/liuyang/test/DI/beans2.xml]: Cannot resolve reference to bean 'daoa' while setting bean property 'daoa'; nested exception is org.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'us' defined ...
- 快捷生成getter和setter方法
选中要生成的名称 shift+alt快捷弹出选款,然后箭头下,然后Alt+A,点击ok
- 三)EasyUI layout
参考文档 http://www.jeasyui.com/documentation/layout.php
- PyCharm创建普通项目配置支持jinja2语法
打开项目的根目录的.idea文件夹中项目名.iml文件(隐藏文件) 打开这个iml文件,在component标签的同级,添加如下代码: <component name="Templat ...
- Web应用与Spring MVC锁session
http是无连接的,所以服务器上并不会为每个用户开辟一个线程,因为没有用户这个说法,但是服务器端是有session的,为了防止一个用户同时有多个请求在处理,spring mvc在处理请求时把sessi ...
- github注册流程
- RabbitMQ.Bus
一个.netcore下的,十分简单的rabbitmq封装,基于RabbitMQ.Client Nuget https://www.nuget.org/packages/RabbitMQ.Bus/ ht ...
- 'System.ValueTuple, Version=0.0.0.0 required for Add-Migration on .NET 4.6.1 Class Library
https://stackoverflow.com/questions/45978173/system-valuetuple-version-0-0-0-0-required-for-add-migr ...
- mvc4验证码&输出图像的处理方式
/// <summary> /// 绘制验证码 /// </summary> /// <returns></returns> public Action ...
- ref和out params
ref和out都对函数参数采用引用传递形式——不管是值类型参数还是引用类型参数,并且定义函数和调用函数时都必须显示生命该参数为 ref/out形式.两者都可以使函数传回多个结果. ref 类似于 PH ...