Finding sum of average sub aggregations

萝らか妹 提交于 2019-12-24 19:20:35

问题


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:

"type": "parsing_exception", "reason": "Unexpected token VALUE_STRING [field] in [group_by_sum]",

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?


回答1:


Your group_by_sum aggregation needs to be written like this:

    "group_by_sum": {
      "sum_bucket": {
        "buckets_path": "group_by_carrier>group_by_avg"
      }
    }


来源:https://stackoverflow.com/questions/45268131/finding-sum-of-average-sub-aggregations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!