How to get aggregation bucket keys in the term query block in the same query?
Query
{
"size": 0,
"query": {....},
"aggs": {
"customerId": {
"composite": {
"sources": [
{
"customerId": {
"terms": {
"field": "customerId"
}
}
}
]
},
"aggs": {
"items_count": {
"cardinality": {
"field": "itemId"
}
},
"item_count_bucket_sort": {
"bucket_sort": {
"size": 2,
"sort": [
{
"items_count": {
"order": "desc"
}
}
]
}
}
}
}
}
}
Output
{
"took": 71,
"timed_out": false,
"_shards": {
"total": 15,
"successful": 15,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 173980,
"max_score": 0,
"hits": [x]
},
"aggregations": {
"customerId": {
"after_key": {
"customerId": "CUST000000010"
},
"buckets": [
{
"key": {
"customerId": "CUST000000007"
},
"doc_count": 12,
"items_count": {
"value": 4
}
},
{
"key": {
"customerId": "CUST000000008"
},
"doc_count": 10,
"items_count": {
"value": 4
}
}
]
}
}
}
In the above output received customerId, need to set in the term query block.