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使用的更多相关文章

  1. Elasticsearch Painless script编程

    我们之前看见了在Elasticsearch里的ingest node里,我们可以通过以下processor的处理帮我们处理我们的一些数据.它们的功能是非常具体而明确的.那么在Elasticsearch ...

  2. xss实例-输出在<script></script>之间的情况

    1. 我们找到这么一个点,也是输入和输出都未过滤的一个点.相比教程第一例,其特殊之处在于,是输出在了 <script>[输出]</script>之间. http://activ ...

  3. 哪种写法更好?<script></script> vs/or <script type=”text/javasript”></script>

    一直很奇怪 哪种写法更好<script type=“text/javascript”>…</script> or <script>…</script>? ...

  4. <script>, <script async>, <script defer> 三种标签的区别

    <script>, <script async>, <script defer> 三种标签的区别 <script>标签 阻塞html parsing 脚 ...

  5. Vue <script></script>区域使用filter过滤器

    Vue中过滤器(filter)的功能高度提取,便于使用,前端小伙伴们使用的频率很高.但大多数都是在模板区域来使用. 如果要在脚本区域, 也就是来使用已经定义好过滤器功能,该如何去做呢? 难道需要在ut ...

  6. elasticSearch script api

    Package org.elasticsearch.script Support for running user provided scripts (in the request, in clust ...

  7. 页面中多个script块之间的关系

     一:函数声明与函数定义表达式在函数调用间的区别 <script type="text/javascript"> doA(); var doA = function(a ...

  8. javaScript中的小细节-script标签中的预解析

    首先介绍预解析,虽然预解析字面意思很好理解,但是却是出坑出的最多的地方,也是bug经常会有的地方,利用好预解析的特性可以解决很多问题,并且提高代码的质量及数量,浏览器在解析代码前会把变量的声明和函数( ...

  9. JS中script词法分析

    核心:JS中的script是分段执行的. <script> var i = 10; </script> <script> alert(i); </script ...

随机推荐

  1. libxml2

    http://www.xmlsoft.org/downloads.html   建议直接用openscenegraph下载的3rdparty:http://www.openscenegraph.org ...

  2. Android--iOS抓取崩溃日志

    android闪退获取日志方法: 1.下载adb工具包 2.注意事项 请确保电脑上只连接了一台手机设备(最好只连接一条USB线),同时确保手机已开启USB调试模式(可通过手机助手查看连接状态) 3.A ...

  3. sqpark编译时maven的pom文件内容(org.apachetype.maven.apachetypes:maven.archetypequickstat)

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  4. nginx中级应用

    1.安装监控模块 Nginx中的stub_status模块主要用于查看Nginx的一些状态信息. 本模块默认是不会编译进Nginx的,如果你要使用该模块,则要在编译安装Nginx时指定: . /con ...

  5. Android-Activity横竖屏切换不杀死Activity 并监听横竖屏切换

    在上一篇博客,Android-Activity临时数据的保存,中讲解到,当发生横竖屏切换的时候,系统会杀死Activity并重新启动Activity 系统会杀死Activity 12-12 08:11 ...

  6. 【C#】泛型

    泛型是一个非常有用的技术,在博客园里面有太多说到泛型的好文章,这里我推荐一篇我个人觉得非常全面,也非常齐全的文章. (重造轮子很傻!!!) C# -- 泛型(1) C# -- 泛型(2) C# -- ...

  7. 利用PhotoShop对大图像进行等分切片

    图文介绍利用PhotoShop等分切图 1.调用切片工具,右键选择划分切片 2.指定水平划分.垂直划分的等分数量,点击确定 3.在文件菜单中选择存储为... 4.配置图像质量参数.点击存储.指定存储位 ...

  8. Linux下配置Apache为多端口

    1.打开Apache的配置文件httpd.conf,在Listen 80处另起一行输入Listen 8080(监听8080端口),要想再添加端口可依次添加 2.在httpd.conf文件最后一行添加: ...

  9. Inno Setup卸载时注销bho

    Inno setup是一个制作安装包的免费工具,比如你用Qt开发完成一款软件,拿Inno setup打个安装包甩给客户安装就好了. 但是bho插件在注册后,万一用户卸载软件时,bho插件还是躺在管理加 ...

  10. OCP 052最新题库还有答案收集整理-第26题

    26.In which state can you back up a database in ARCHIVELOGMODE using RMAN? A. NOMOUNT, MOUNT, AND OP ...