Bucket selector aggregation context
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
Use a Painless script in an bucket_selector aggregation to determine if a bucket should be retained or filtered out.
params(Map, read-only)- User-defined parameters passed in as part of the query. The parameters include values defined as part of the
buckets_path.
- boolean
- True if the bucket should be retained, false if the bucket should be filtered out.
The standard Painless API is available.
To run the example, first install the eCommerce sample data.
The following request filters out low-performing manufacturers and focuses only on brands with significant sales volume. The query groups orders by manufacturer, counts total orders for each brand, then uses a bucket selector to show only manufacturers with 50 or more orders.
GET kibana_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"manufacturers": {
"terms": {
"field": "manufacturer.keyword"
},
"aggs": {
"total_orders": {
"value_count": {
"field": "order_id"
}
},
"high_volume_filter": {
"bucket_selector": {
"buckets_path": {
"order_count": "total_orders"
},
"script": {
"source": "params.order_count >= 50"
}
}
}
}
}
}
}