# Elasticsearch composite aggregate query on nested fields

**URL:** https://discuss.elastic.co/t/elasticsearch-composite-aggregate-query-on-nested-fields/247260
**Category:** Elasticsearch
**Created:** [September 2, 2020, 3:47pm UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregate-query-on-nested-fields/247260 "2020-09-02T15:47:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MCRj](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@MCRj](https://discuss.elastic.co/u/MCRj)
#### Post date: [September 2, 2020, 3:47pm UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregate-query-on-nested-fields/247260/1 "2020-09-02T15:47:21Z")

</div>

I've a question on an aggregation on nested objects. Document is like:

```auto
{
    "features": [{
            "key": "key1",
            "values": ["A", "B"]
        },
        {
            "key": "key2",
            "values": ["C", "D"]
        },
        {
            "key": "key2",
            "values": ["E"]
        }
    ]

```

where 'features' is a nested object. I can aggregate and get distinct values from key and values, but I need to get a combined aggregation, where I need all keys with their associated values, like:

key1 -\> A,B  
key2 -\> C,D,E

Is composite aggregation that has to be used? Or which is the proper aggregation to use? Java samples are also welcome!

Thanks!!!

---

<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: [September 30, 2020, 3:47pm UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregate-query-on-nested-fields/247260/2 "2020-09-30T15:47:22Z")

</div>

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