ElasticSearch怎么同时对两个字段做sum聚合查询
1个回答
展开全部
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();
...
.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();
...
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询