Hi,
Elasticsearch: 8.3.3
Below i use composite aggregation, then filtered aggregation and finally bucket selector. It returns all the buckets in a paginated way. But what I need is total count of buckets, not the buckets itself. Is there a solution to this? Since the unique number of customers is too big I use composite agregation instead of normal bucket aggregation.
{
"query": {
"bool": {
"filter": [
{
"terms": {
"yearweek": [
"2024-18", "2024-19", "2024-20", "2024-21", "2024-22", "2024-23",
"2024-24", "2024-25", "2024-26", "2024-27", "2024-28", "2024-29",
"2024-30", "2024-31"
]
}
}
]
}
},
"aggs": {
"customers_composite": {
"composite": {
"sources": [
{"customers_agg": {"terms": {"field": "customer.keyword"}}}
],
"size": 10000
},
"aggs": {
"last_week_count": {
"filter": {"term": {"yearweek": "2024-31"}}
},
"previous_weeks_count": {
"filter": {
"terms": {
"yearweek": [
"2024-18", "2024-19", "2024-20", "2024-21", "2024-22", "2024-23",
"2024-24", "2024-25", "2024-26", "2024-27", "2024-28", "2024-29",
"2024-30"
]
}
}
},
"only_last_period": {
"bucket_selector": {
"buckets_path": {
"currentPeriod": "last_week_count._count",
"previousPeriods": "previous_weeks_count._count"
},
"script": "params.currentPeriod > 0 && params.previousPeriods == 0"
}
}
}
}
}
}