elasticSearch用java查询问题
发布网友
发布时间:2022-04-20 16:43
我来回答
共2个回答
热心网友
时间:2023-07-11 06:55
你这个查询用filter、must皆可,推荐filter
String index = "indexName"; // 你的index名称
String type = "my_table";
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
// boolQuery.must(QueryBuilders.termQuery("a", 1));
// boolQuery.must(QueryBuilders.termsQuery("b", 2, 3));
boolQuery.filter(QueryBuilders.termQuery("a", 1));
boolQuery.filter(QueryBuilders.termsQuery("b", 2, 3));
SearchResponse searchResponse = client.prepareSearch(index).setTypes(type)
.setQuery(boolQuery)
.addSort("c", SortOrder.ASC)
.addSort("d", SortOrder.ASC)
.storedFields("c", "d")
.get();
热心网友
时间:2023-07-11 06:55
查询器里的should是或,must是且