java RestHighLevelClient 多条件and 查询
时间: 2023-11-08 10:07:20 浏览: 78
使用 Java RestHighLevelClient 进行多条件 And 查询可以通过构建 BoolQuery 来实现。
以下是一个示例代码:
```java
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", 9200, "http"))
);
SearchRequest searchRequest = new SearchRequest("index-name");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchQuery("field1", "value1"));
boolQueryBuilder.must(QueryBuilders.matchQuery("field2", "value2"));
searchSourceBuilder.query(boolQueryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
```
在上面的示例中,我们构建了一个 BoolQuery,并使用 must 方法将多个 MatchQuery 组合在一起,表示这些条件必须全部满足。这样就可以实现多条件 And 查询。
阅读全文