SearchSourceBuilder
时间: 2023-06-13 07:05:00 浏览: 164
ResourceBuilder
SearchSourceBuilder是Elasticsearch Java API中的一个类,用于构建搜索请求体,可以通过该类设置各种搜索条件,例如查询语句、过滤条件、排序规则、分页等等。SearchSourceBuilder可以通过以下方式创建:
```
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
```
然后可以通过该对象设置各种搜索条件,例如:
```
searchSourceBuilder.query(QueryBuilders.matchQuery("title", "Elasticsearch"));
searchSourceBuilder.from(0);
searchSourceBuilder.size(10);
searchSourceBuilder.sort(new ScoreSortBuilder().order(SortOrder.DESC));
searchSourceBuilder.sort(new FieldSortBuilder("create_time").order(SortOrder.DESC));
```
最后将SearchSourceBuilder对象传递给SearchRequest对象即可发起搜索请求:
```
SearchRequest searchRequest = new SearchRequest("index_name");
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
```
阅读全文