java实现ElasticSerach RestHighLevelClient 高亮,分页,范围查询
时间: 2023-11-08 20:07:08 浏览: 101
好的,关于 Java 实现 ElasticSearch RestHighLevelClient 的高亮、分页和范围查询,可以参考以下代码:
1. 高亮查询:
```
SearchRequest searchRequest = new SearchRequest(indexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
HighlightBuilder highlightBuilder = new HighlightBuilder();
highlightBuilder.field("fieldName");
highlightBuilder.requireFieldMatch(false);
highlightBuilder.preTags("<em>");
highlightBuilder.postTags("</em>");
searchSourceBuilder.highlighter(highlightBuilder);
searchRequest.source(searchSourceBuilder);
```
2. 分页查询:
```
SearchRequest searchRequest = new SearchRequest(indexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.from(0);
searchSourceBuilder.size(10);
searchRequest.source(searchSourceBuilder);
```
3. 范围查询:
```
SearchRequest searchRequest = new SearchRequest(indexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("fieldName");
rangeQueryBuilder.gt("value1");
rangeQueryBuilder.lt("value2");
searchSourceBuilder.query(rangeQueryBuilder);
searchRequest.source(searchSourceBuilder);
```
希望这些代码可以帮助到你。
阅读全文