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\": {
What I do is use something like the following query:
"aggs" : {
"products" : {
"filter" : { "term": { "item.category": "children" }},
"aggs" : {
"count" : {
"terms" : {
"script": "doc['item.id'].value + ':' + doc['item.name'].value"
}
}
}
}
}
Which returns something like this:
...
"aggregations" : {
"products" : {
"doc_count" : 1050,
"count" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "x2_90QBj9k:Baby Oil",
"doc_count" : 45
},
...
]
...
And then I can use a string operation on bucket[i]["key"], for each i in a loop, to extract the relevant field.