spring-data-elasticsearch -> restHighLevelClient

 


public void searchWithScoreNew(NativeSearchQueryBuilder queryBuilder) throws IOException {
String realIndexName = "item";
SearchRequest searchRequest = new SearchRequest(realIndexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
NativeSearchQuery nativeSearchQuery = queryBuilder.build();
searchSourceBuilder.query(nativeSearchQuery.getQuery());
searchSourceBuilder.postFilter(nativeSearchQuery.getFilter());
List<SortBuilder> elasticsearchSorts = nativeSearchQuery.getElasticsearchSorts();
if (CollectionUtils.isNotEmpty(elasticsearchSorts)) {
elasticsearchSorts.forEach(searchSourceBuilder::sort);
}
searchSourceBuilder.from(Math.toIntExact(nativeSearchQuery.getPageable().getOffset()));
searchSourceBuilder.size(nativeSearchQuery.getPageable().getPageSize());
searchSourceBuilder.trackScores(true);
    searchRequest.source(searchSourceBuilder);
SearchResponse response = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
SearchHits hits = response.getHits();
if (hits.getHits().length > 0) {
log.info("searchWithScoreNew,maxScore:{},hits:{}", hits.getMaxScore(), JSON.toJSONString(Arrays.asList(hits.getHits())));
}
}
 

org.springframework.data.elasticsearch.core.RequestFactory Maven / Gradle / Ivy

https://jar-download.com/artifacts/org.springframework.data/spring-data-elasticsearch/4.1.7/source-code/org/springframework/data/elasticsearch/core/RequestFactory.java

posted @ 2023-04-01 11:51  parkdifferent  阅读(47)  评论(0编辑  收藏  举报