我在搜索请求中有一系列连续的聚合:
"aggs": {
"nested_max": {
"nested": {
"path": "questionResponses"
},
"aggs": {
"filter_max": {
"filter": {
"term": {
"questionResponses.key": "announcement.question.tri"
}
},
"aggs": {
"agg_max": {
"max": {
"field": "questionResponses.numericValue"
}
}
}
}
}
}
有人可以帮我将这部分请求转换为Java代码:
我做了什么(但不起作用):
NestedAggregationBuilder maxAggregation =
AggregationBuilders.nested("nested_max", questionResponses)
.subAggregation(AggregationBuilders.filter("filter_max", QueryBuilders.termQuery("announcement.question.tri", "announcement.question.tri")))
.subAggregation(AggregationBuilders.max("agg_max").field("questionResponses.numericValue"));
最佳答案
您应该将agg_max子聚合添加到filter_max aggs。
filterMax = AggregationBuilders.filter(....);
aggMax = AggregationBuilders.max("agg_max")..;
NestedAggregationBuilder maxAggregation =
AggregationBuilders.nested("nested_max", questionResponses)
.subAggregation(aggFilterMax.subAggregation(aggMax));