How can I add a new key called \'agency_name\' in my output bucket.
I am running an aggregation code as shown below
{
\"aggs\": {
\"name\": {
You can use the top hits aggregation like in the link below. The format will be slightly different since creating the extra aggregation will embed the agency name under another 'hits' key.
Adding additional fields to ElasticSearch terms aggregation
{
"aggs": {
"name": {
"terms": {
"field": "agency_code"
},
"aggs": {
"agency_names" : {
"top_hits": {
size: 1,
_source: {
include: ['agency_name']
}
}
}
}
}
}
}