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": {
"terms": {
"field": "agency_code"
}
}
}
}
I will be getting the out put as
"aggregations": {
"name": {
"doc_count_error_upper_bound": 130,
"sum_other_doc_count": 39921,
"buckets": [
{
"key": "1000",
"doc_count": 105163
},
{
"key": "2100",
"doc_count": 43006
}
]
}
}
While displaying I need to show the agency name, code and doc_count
How can I modify the aggregation query so that I could get the below format. I am new to ElasticSearch, not sure how to fix this
"aggregations": {
"name": {
"doc_count_error_upper_bound": 130,
"sum_other_doc_count": 39921,
"buckets": [
{
"key": "1000",
"doc_count": 105163,
"agency_name": 'Agent 1'
},
{
"key": "2100",
"doc_count": 43006,
"agency_name": 'Agent 2'
}
]
}
}
Sample Data in ElasticSearch (fields are analysed)
{
"_index": "feeds",
"_type": "news",
"_id": "22005",
"_version": 1,
"_score": 1,
"_source": {
"id": 22005,
"name": "Test News",
"agency_name": "Agent 1",
"agency_code": "1000",
}
}
docvalue_fields
instead of_source
in the above query? I'm aware that they are 2 different things, just ask in term of performance – Propensity