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\": {
I think you would need to add another "aggs" to it. But it would not be in the format in which you want but as another field in the output , reason being currently you are aggregating based on "agency_code" and the doc_count shows how many times the particular agency code occurs. Now when you want to aggregate it based on "agency_name" the field might in different documents than "agency_code" and in different numbers as well , if they always exist in pair than this parent-child indexing might be of some help.
https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-parent-child.html