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

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

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

1 Like

worked beautifully, thank you.