本文介绍了求平均子聚合的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想得到一个子聚合的总和.例如,我先按智能手机分组,然后按运营商分组,然后找到该特定智能手机的每个运营商的平均价格.我想获取每部智能手机的所有运营商的平均价格之和.所以本质上,我想要这样的东西:
I'd like to get the sum of a sub aggregation. For example, I'm grouping by smartphones, then by carrier, and then I'm finding the average price of each carrier for that particular smartphone. I'd like to get the sum of the average prices for all carriers for each smartphone. So essentially, I want something like this:
{
"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"
}
}
}
}
}
}
当我尝试执行此查询时,出现错误消息:
When I try doing this query, I get an error saying:
因此本质上,我想获取特定智能手机的所有运营商平均值的总和.有办法吗?
So essentially I want to get the sum of the averages of all carriers for a particular smartphone. Is there a way to get this?
推荐答案
您的group_by_sum
聚合需要这样写:
"group_by_sum": {
"sum_bucket": {
"buckets_path": "group_by_carrier>group_by_avg"
}
}
这篇关于求平均子聚合的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!