首页 > 编程语言 >Elasticsearch自定义评分+折叠Java实现

Elasticsearch自定义评分+折叠Java实现

时间:2022-11-10 16:02:31浏览次数:54  
标签:Java 自定义 System Elasticsearch println new FunctionScoreQueryBuilder out innerHit

QueryBuilder boolQueryBuilder = query.getBoolQueryBuilder(localInfoRequest, QueryEnum.termsQuery);   FunctionScoreQueryBuilder.FilterFunctionBuilder[] filterFunctionBuilders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[3]; ScoreFunctionBuilder score = new FieldValueFactorFunctionBuilder("type").factor(1.0f); filterFunctionBuilders[0] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(score);   ScoreFunctionBuilder score1 = new FieldValueFactorFunctionBuilder("clipId").factor(1.0f); filterFunctionBuilders[1] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(score1);   ScoreFunctionBuilder score2 = new FieldValueFactorFunctionBuilder("partnerId").factor(1.0f); filterFunctionBuilders[2] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(score2);   FunctionScoreQueryBuilder functionScoreQuery = QueryBuilders.functionScoreQuery(boolQueryBuilder, filterFunctionBuilders) .scoreMode(FunctionScoreQuery.ScoreMode.SUM) .boostMode(CombineFunction.SUM); System.out.println(functionScoreQuery);   CollapseBuilder collapse = new CollapseBuilder("partnerId"); InnerHitBuilder innerHit = new InnerHitBuilder(); innerHit.setName("collapse"); innerHit.setFrom(0); innerHit.setSize(1); innerHit.setTrackScores(true); innerHit.setIgnoreUnmapped(true); innerHit.addSort(SortBuilders.fieldSort("serviceId").order(SortOrder.DESC)).addSort(SortBuilders.geoDistanceSort("point",30.223,-70.334)); collapse.setInnerHits(innerHit);   SearchSourceBuilder builder = new SearchSourceBuilder() .query(functionScoreQuery) .collapse(collapse) .from(0) .size(10) .sort(SortBuilders.fieldSort("type").order(SortOrder.DESC)) .sort(SortBuilders.fieldSort("partnerId").order(SortOrder.DESC));   System.out.println(builder);   SearchRequest request = new SearchRequest(IndexEnum.LocalInfo.getIndex()) .source(builder) .searchType(SearchType.QUERY_THEN_FETCH); SearchResponse response = client.search(request, RequestOptions.DEFAULT);   SearchHit[] hits = response.getHits().getHits(); for (SearchHit hit : hits) { System.out.println("Hits"); System.out.println(hit.getId()); for (SearchHits inner : hit.getInnerHits().values()) { System.out.println("InnerHits"); for (SearchHit innerCollapse : inner.getHits()) { System.out.println(innerCollapse.getId()); } } } Map<string, searchhits=""> innerHits = hits[0].getInnerHits(); Optional first = innerHits.values().stream().findFirst(); LocalInfo localInfo = JsonUtil.transFormationMap(first.get().getHits()[0].getSourceAsString(), LocalInfo.class); System.out.println(JsonUtil.transFormationJson(localInfo));

标签:Java,自定义,System,Elasticsearch,println,new,FunctionScoreQueryBuilder,out,innerHit
From: https://www.cnblogs.com/qiezi777/p/16877321.html

相关文章

  • 【java八股】ArrayList自动扩容过程
    ArrayList是一个数组类型的存储容器,默认大小是10个容量的数组,容量也可以在构件ArrayList的时候通过构造器指定大小,当容量不够时会进行自动扩容到原来的1.5倍,由于底层是数组......
  • JavaSE实现国际化操作(十五)
    勿以恶小而为之,勿以善小而不为--------------------------刘备劝诸君,多行善事积福报,莫作恶上一章简单介绍了Java批量修改文件名称(十四)),如果没有看过,​​请观看上一章​​......
  • SpringBoot自定义Starter(二十四)
    即使有一天,我放弃了自己的身体,也请你,不要放弃我,我亲爱的灵魂.上一章简单介绍了Spring_Session解决Session共享的问题(二十三),如果没有看过,​​请观看上一章​​一.自定义......
  • 微信小程序自定义showModel后怎么获取获取input框输入值
    先看下效果自己调样式太好玩了哈哈哈参考官方文档用官方的直接copy过来就可以实现https://developers.weixin.qq.com/miniprogram/dev/component/input.htmlwxml......
  • SpringBoot自定义日志Starter(二十五)
    即使有一天,我放弃了自己的身体,也请你,不要放弃我,我亲爱的灵魂.上一章简单介绍了SpringBoot自定义Starter(二十四),如果没有看过,​​请观看上一章​​一.AOP实现日志功能......
  • el-calendar 自定义我的日程
    效果图1. el-calendar官方文档内容太少,具体需要css样式,可以根据ui设置自行修改,一下的代码只展示JS的逻辑.2. 遍历日期,确定显示内容<el-calendarv-model="value"><te......
  • java 判断string是否为数字的方法
    1、用JAVA自带的函数1publicstaticbooleanisNumeric(Stringstr){2for(inti=0;i<str.length();i++){3System.out.println(st......
  • linux安装java
    1.在/usr下新建java2.上传安装包到java,并解压tar-xvfjdk....tar.gz3.ln-s/usr/java/jdk1.8.0_351/usr/jdk 设置链接,节约目录长度4.vim/etc/profile 5. 配置......
  • eclipse搭建第一个java web应用
    Eslicpe安装下载地址,https://www.eclipse.org/downloads/tomcat服务器安装下载地址,https://tomcat.apache.org/download-80.cgiDynamicwebproject如果你的软件里没有它,请......
  • 用java做一个内存缓存
    项目中对接第三方系统需要先获取认证token后,才能调用其他接口,token的有效期(固定为1小时),如果使用redis来做,十分简单,设置redis缓存加上1个小时有效期就可以解决。现在需要自......