# How to return more than one field in a result of aggregations

**URL:** <https://discuss.elastic.co/t/how-to-return-more-than-one-field-in-a-result-of-aggregations/54825>\
**Category:** Elasticsearch\
**Created:** [July 6, 2016, 1:29pm UTC](https://discuss.elastic.co/t/how-to-return-more-than-one-field-in-a-result-of-aggregations/54825 "2016-07-06T13:29:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelr](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@samuelr](https://discuss.elastic.co/u/samuelr)\
**Post date:** [July 6, 2016, 1:29pm UTC](https://discuss.elastic.co/t/how-to-return-more-than-one-field-in-a-result-of-aggregations/54825/1 "2016-07-06T13:29:03Z")

</div>

hello, I need a help to know how to do, and if possible, return more than one field in a result of aggregation.  
i have this agg:

{  
"size": 0,  
"aggs" : {  
"bairros" : {  
"terms" : {  
"field" : "bairro",  
"size":0  
}  
}  
}  
}

that it returning me, for example:

"buckets": [  
{  
"key": "Santa Helena",  
"doc\_count": 640  
},  
{  
"key": "Ouro Verde",  
"doc\_count": 637  
}  
]

I need to this agg, return me a field more, "municipio".  
I need that the return is like this for example:

"buckets": [  
{  
"key": "Santa Helena",  
"municipio": "something",  
"doc\_count": 640  
}  
]

how can I change my agg, to make this possible?

Thank you so much

---

<div class="post-metadata">

**Author:** ![chris16](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@chris16](https://discuss.elastic.co/u/chris16)\
**Post date:** [July 6, 2016, 2:16pm UTC](https://discuss.elastic.co/t/how-to-return-more-than-one-field-in-a-result-of-aggregations/54825/2 "2016-07-06T14:16:02Z")

</div>

You could use the top hits aggregation instead: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)

---

<div class="post-metadata">

**Author:** ![samuelr](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@samuelr](https://discuss.elastic.co/u/samuelr)\
**Post date:** [July 6, 2016, 4:19pm UTC](https://discuss.elastic.co/t/how-to-return-more-than-one-field-in-a-result-of-aggregations/54825/3 "2016-07-06T16:19:05Z")

</div>

worked beautifully, thank you.

---

<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, 10:37pm UTC](https://discuss.elastic.co/t/how-to-return-more-than-one-field-in-a-result-of-aggregations/54825/4 "2017-07-05T22:37:37Z")

</div>


