# Finding sum of average aggregations

**URL:** <https://discuss.elastic.co/t/finding-sum-of-average-aggregations/94156>\
**Category:** Elasticsearch\
**Created:** [July 21, 2017, 7:46pm UTC](https://discuss.elastic.co/t/finding-sum-of-average-aggregations/94156 "2017-07-21T19:46:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamA](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@SamA](https://discuss.elastic.co/u/SamA)\
**Post date:** [July 21, 2017, 7:46pm UTC](https://discuss.elastic.co/t/finding-sum-of-average-aggregations/94156/1 "2017-07-21T19:46:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 18, 2017, 7:46pm UTC](https://discuss.elastic.co/t/finding-sum-of-average-aggregations/94156/2 "2017-08-18T19:46:32Z")

</div>

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