我想获得子聚合的总和。例如,我通过智能手机分组,然后通过运营商分组,然后我找到该特定智能手机的每个运营商的平均价格。我想得到每款智能手机所有运营商平均价格的总和。基本上,我想要这样的东西:
{
"aggs": {
"group_by_smartphones": {
"terms": {
"field": "smartphone",
"order": {
"_term": "asc"
},
"size": 200
},
"aggs": {
"group_by_carrier": {
"terms": {
"field": "carrier",
"order": {
"group_by_avg": "desc"
}
},
"aggs": {
"group_by_avg": {
"avg": {
"field": "price"
}
}
}
},
"group_by_sum": {
"sum_bucket": {
"field": "group_by_smartphones>group_by_carrier>group_by_avg"
}
}
}
}
}
}
当我尝试执行此查询时,我收到错误消息:
“type”:“parsing_exception”,“reason”:“意外的令牌VALUE_STRING [group_by_sum]中的[field]“,
所以基本上我想得到特定智能手机所有运营商平均值的总和。有没有办法得到这个?
答案 0 :(得分:0)
您的group_by_sum
汇总需要这样写:
"group_by_sum": {
"sum_bucket": {
"buckets_path": "group_by_carrier>group_by_avg"
}
}