# Nested output buckets' aggregation

**URL:** <https://discuss.elastic.co/t/nested-output-buckets-aggregation/45626>\
**Category:** Elasticsearch\
**Created:** [March 28, 2016, 9:02pm UTC](https://discuss.elastic.co/t/nested-output-buckets-aggregation/45626 "2016-03-28T21:02:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![esap](https://avatars.discourse-cdn.com/v4/letter/e/7c8e57/32.png) [@esap](https://discuss.elastic.co/u/esap)\
**Post date:** [March 28, 2016, 9:02pm UTC](https://discuss.elastic.co/t/nested-output-buckets-aggregation/45626/1 "2016-03-28T21:02:31Z")

</div>

Here is my doc type: vehicles is a nested type.

document1 -

```
{
  "customerAge": 30,
  "vehicles": [
    {
      "brand": "Altima",
      "year": 2005
    },
    {
      "brand": "Corolla",
      "year": 2006
    },
    {
      "brand": "Camry",
      "year": 2005
    }
  ]
}

```

document2 -

```
{
  "customerAge": 50,
  "vehicles": [
    {
      "brand": "Altima",
      "year": 2009
    },
    {
      "brand": "Corolla",
      "year": 2010
    }
  ]
}

```

I am trying to create buckets of vehicle brand and calculate the averages of customer age. So in this example "Altima" bucket's average customer age will be 40.

I tried this query and the averages are null.

Could someone please help what am I doing incorrectly?

```
{
   "size": 0,
   "aggs": {
      "nestedtop": {
         "nested": {
            "path": "vehicles"
         },
         "aggs": {
            "testagg": {
               "terms": {
                  "field": "vehicles.brand"
               },
               "aggs": {
                  "filterx3939d": {
                     "filter": {
                        "match_all": {}
                     },
                     "aggs": {
                        "filterx3939d": {
                           "min": {
                              "field": "customerAge"
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}
```

---

<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:** [July 5, 2017, 11:01pm UTC](https://discuss.elastic.co/t/nested-output-buckets-aggregation/45626/2 "2017-07-05T23:01:36Z")

</div>

Closed on July 5, 2017, 11:01pm UTC


