I use an ElasticSearch search request with composite aggregation in order to get a list of all different indexed values of one specific field. The result gives me all I need, but I don't need all that info contained.
Request:
{
"aggs": {
"my_buckets": {
"composite": {
"size": 10000,
"sources": [{
"my_stoid": {
"terms": {
"field": "stoId"
}
}
}
]
}
}
},
"size": 0
}
Response:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 15,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"composite#my_buckets": {
"after_key": {
"my_stoid": "KV"
},
"buckets": [{
"key": {
"my_stoid": "1"
},
"doc_count": 5
}, {
"key": {
"my_stoid": "2102"
},
"doc_count": 1
}, {
"key": {
"my_stoid": "8000"
},
"doc_count": 1
}, {
"key": {
"my_stoid": "9999"
},
"doc_count": 6
}, {
"key": {
"my_stoid": "KB"
},
"doc_count": 1
}, {
"key": {
"my_stoid": "KV"
},
"doc_count": 1
}
]
}
}
}
I only need the values "1", "2102", "8000"... from the buckets. Like so:
"buckets": ["1", "2102", "8000", "9999", "KB", "KV"]
Is there a way to achieve this?
A similar question in the Elasticsearch discussion forum got this answer:
The doc count is very low cost to calculate since it is just maintaining and incrementing a single long for each bucket. The cost of maintaining and updating sub aggregations for each bucket will be much more than this so it shouldn't significantly impact the performance of your aggregation request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With