Elasticsearch:提高某字段评分

  • 2019 年 11 月 14 日
  • 筆記

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/chengyuqiang/article/details/103042827

    public Iterator<DocBean> search(String key,Integer pageNum,Integer pageSize) {          BoolQueryBuilder boolQueryBuilder= QueryBuilders.boolQuery()                  .should(QueryBuilders.matchQuery("firstCode",key).boost(2)) //提高评分                  .should(QueryBuilders.matchQuery("secordCode",key).boost(2))//提高评分                  .should(QueryBuilders.matchQuery("content",key));          NativeSearchQuery nativeSearchQuery=new NativeSearchQueryBuilder()                  .withQuery(boolQueryBuilder)                  .withPageable(PageRequest.of(pageNum,pageSize))                  .build();          long count=elasticsearchTemplate.count(nativeSearchQuery, DocBean.class);          AggregatedPage<DocBean> page= elasticsearchTemplate.queryForPage(nativeSearchQuery, DocBean.class, new MyMapper());          return page.iterator();      }