Elasticsearch:提高某字段评分

    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();
    }
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页