elasticsearch aggs 嵌套查询 多个select 统计/聚合部分查询结果
发布网友
发布时间:2022-05-14 13:27
我来回答
共1个回答
热心网友
时间:2023-10-18 17:12
SearchRequestBuilder srb = client.prepareSearch(indexName)
.setTypes(typeName)
.setSearchType(SearchType.QUERY_THEN_FETCH);
...
TermsBuilder field1Terms = AggregationBuilders.terms("group_by_field1").field("field1").size(0);
SumBuilder field2Sum = AggregationBuilders.sum("sum_field2").field("field2");
SumBuilder field3Sum = AggregationBuilders.sum("sum_field3").field("field3");
field1Terms.subAggregation(field2Sum ).subAggregation(field3Sum );
...
srb.addAggregation(pIdTerms);
...
SearchResponse sr = srb.execute().actionGet();
...