Finding sum of average aggregations

I'd like to get the sum of a sub aggregation. For example, I have group by smartphones, group by carrier and then the average price for that carrier. I'd like to get the sum of the average prices for all carriers for a specific 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?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.