java写一个es的聚合查询,功能为匹配索引一下面的字段一、字段二,结果按字段三的值不同来计算命中数量
时间: 2023-03-07 19:14:04 浏览: 111
java使用es链接进行查询
你可以使用以下Java代码来编写ES聚合查询:SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); // 聚合查询
AggregationBuilder aggregationBuilder = AggregationBuilders.terms("agg_name")
.field("field_three")
.subAggregation(AggregationBuilders.filter("filed_one_two_filter")
.filter(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("field_one", "value_one"))
.must(QueryBuilders.termQuery("field_two", "value_two"))
)
);searchSourceBuilder.aggregation(aggregationBuilder);
searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest);
阅读全文