- Painless Scripting Language: other versions:
- Painless Guide
- Painless Language Specification
- Painless contexts
- Context example data
- Runtime fields context
- Ingest processor context
- Update context
- Update by query context
- Reindex context
- Sort context
- Similarity context
- Weight context
- Score context
- Field context
- Filter context
- Minimum should match context
- Metric aggregation initialization context
- Metric aggregation map context
- Metric aggregation combine context
- Metric aggregation reduce context
- Bucket script aggregation context
- Bucket selector aggregation context
- Analysis Predicate Context
- Watcher condition context
- Watcher transform context
- Painless API Reference
- Shared API
- Aggregation Selector API
- Aggs API
- Aggs Combine API
- Aggs Init API
- Aggs Map API
- Aggs Reduce API
- Analysis API
- Bucket Aggregation API
- Field API
- Filter API
- Ingest API
- Interval API
- Moving Function API
- Number Sort API
- Painless Test API
- Processor Conditional API
- Score API
- Script Heuristic API
- Similarity API
- Similarity Weight API
- String Sort API
- Template API
- Terms Set API
- Update API
- Watcher Condition API
- Watcher Transform API
- Xpack Template API
This documentation contains work-in-progress information for future Elastic Stack and Cloud releases. Use the version selector to view supported release docs. It also contains some Elastic Cloud serverless information. Check out our serverless docs for more details.
Bucket script aggregation context
editBucket script aggregation context
editUse a Painless script in an
bucket_script
pipeline aggregation
to calculate a value as a result in a bucket.
Variables
edit-
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
.
Return
edit- numeric
- The calculated value as the result.
API
editThe standard Painless API is available.
Example
editTo run this example, first follow the steps in context examples.
The painless context in a bucket_script
aggregation provides a params
map. This map contains both
user-specified custom values, as well as the values from other aggregations specified in the buckets_path
property.
This example takes the values from a min and max aggregation, calculates the difference, and adds the user-specified base_cost to the result:
(params.max - params.min) + params.base_cost
Note that the values are extracted from the params
map. In context, the aggregation looks like this:
GET /seats/_search { "size": 0, "aggs": { "theatres": { "terms": { "field": "theatre", "size": 10 }, "aggs": { "min_cost": { "min": { "field": "cost" } }, "max_cost": { "max": { "field": "cost" } }, "spread_plus_base": { "bucket_script": { "buckets_path": { "min": "min_cost", "max": "max_cost" }, "script": { "params": { "base_cost": 5 }, "source": "(params.max - params.min) + params.base_cost" } } } } } } }
Was this helpful?
Thank you for your feedback.