# Getting multiple average aggregations

**URL:** <https://discuss.elastic.co/t/getting-multiple-average-aggregations/93604>\
**Category:** Elasticsearch\
**Created:** [July 18, 2017, 2:47pm UTC](https://discuss.elastic.co/t/getting-multiple-average-aggregations/93604 "2017-07-18T14:47:05Z")\
**Posts on this page:** 3\
**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 18, 2017, 2:47pm UTC](https://discuss.elastic.co/t/getting-multiple-average-aggregations/93604/1 "2017-07-18T14:47:06Z")

</div>

I have a query where I'm grouping by smartphone and then by carrier. Inside these nested aggregations, I want to find the avg price, rating, and speed of each carrier for that particular smartphone. This is my current query:

```
{
  "aggs": {
    "group_by_smartphone": {
      "terms": {
        "field": "smartphone"
      },
      "aggs": {
        "group_by_carrier": {
          "terms": {
            "field": "carrier"
          },
          "aggs": {
            "group_by_avg_price": {
              "avg": {
                "field": "price"
              }
            }
          },

            "group_by_rating":{
              "avg":{
                "field": "rating"
              }
            }

        }
      }
    }
  }
}

```

With this current query, I'm getting an error saying:

> "type": "parsing\_exception", "reason": "Found two aggregation type definitions in [group\_by\_carrier]: [terms] and [group\_by\_rating]",

How can I fix this in order to display the correct results of each average?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 18, 2017, 2:55pm UTC](https://discuss.elastic.co/t/getting-multiple-average-aggregations/93604/2 "2017-07-18T14:55:32Z")

</div>

You need to put the `group_by_rating` aggregation i side the `aggs` object which is under `group_by_carrier`. Like this:

```auto
{  
   "aggs":{  
      "group_by_smartphone":{  
         "terms":{  
            "field":"smartphone"
         },
         "aggs":{  
            "group_by_carrier":{  
               "terms":{  
                  "field":"carrier"
               },
               "aggs":{  
                  "group_by_avg_price":{  
                     "avg":{  
                        "field":"price"
                     }
                  },
                 "group_by_rating":{  
                    "avg":{  
                       "field":"rating"
                    }
                 }
               }
            }
         }
      }
   }
}

```

---

<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 15, 2017, 2:55pm UTC](https://discuss.elastic.co/t/getting-multiple-average-aggregations/93604/3 "2017-08-15T14:55:53Z")

</div>

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