-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Docs] Add painless context details for bucket_selector #35162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
polyfractal
merged 4 commits into
elastic:master
from
polyfractal:painless_bucket_selector_context
Nov 8, 2018
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
630cb9b
[Docs] Add painless context details for bucket_selector
polyfractal 7f67ac6
review tweaks
polyfractal 3c92990
Merge remote-tracking branch 'origin/master' into painless_bucket_sel…
polyfractal 6672061
Merge remote-tracking branch 'origin/master' into painless_bucket_sel…
polyfractal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
docs/painless/painless-contexts/painless-bucket-selector-agg-context.asciidoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
|
|
||
| [[painless-bucket-selector-agg-context]] | ||
| === Bucket Selector aggregation context | ||
|
|
||
| Use a Painless script in an | ||
| {ref}/search-aggregations-pipeline-bucket-selector-aggregation.html[`bucket_selector` aggregation] | ||
| to determine if a bucket should be retained or filtered out. | ||
|
|
||
| ==== Variables | ||
|
|
||
| `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 | ||
|
|
||
| boolean:: | ||
| True if the the bucket should be retained, false if the bucket should be filtered out. | ||
|
|
||
| ==== API | ||
|
|
||
|
|
||
| To run this example, first follow the steps in <<painless-context-examples, context examples>>. | ||
|
|
||
| The painless context in a `bucket_selector` 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. | ||
|
|
||
| For our example, we are going to find the `max` of each bucket, add in a user-defined "base" value, then keep all | ||
| the buckets that are greater than `10`. | ||
|
|
||
polyfractal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Unlike some other aggregation contexts, the `bucket_selector` context must return a boolean `true`/`false`. | ||
|
|
||
polyfractal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [source,Painless] | ||
| -------------------------------------------------- | ||
| params.max + params.base_cost > 10 | ||
| -------------------------------------------------- | ||
|
|
||
| Note how all the values are being pulled from the `params` map. Also note how the script is in the form of an expression, | ||
| which returns `true`/`false`. In context, the aggregation looks like this: | ||
|
|
||
polyfractal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [source,js] | ||
| -------------------------------------------------- | ||
| GET /seats/_search | ||
| { | ||
| "size": 0, | ||
| "aggs": { | ||
| "theatres": { | ||
| "terms": { | ||
| "field": "theatre", | ||
| "size": 10 | ||
| }, | ||
| "aggs": { | ||
| "max_cost": { | ||
| "max": { | ||
| "field": "cost" | ||
| } | ||
| }, | ||
| "filtering_agg": { | ||
| "bucket_selector": { | ||
| "buckets_path": { <1> | ||
| "max": "max_cost" | ||
| }, | ||
| "script": { | ||
| "params": { | ||
| "base_cost": 5 <2> | ||
| }, | ||
| "source": "params.max + params.base_cost > 10" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| -------------------------------------------------- | ||
| // CONSOLE | ||
| // TEST[setup:seats] | ||
| <1> the `buckets_path` points to the max aggregations (`max_cost`) and adds `max` variables | ||
| to the `params` map | ||
| <2> the user-specified `base_cost` is added in the script's `params` section, which is also added to the | ||
| `params` variable for use in the script. | ||
polyfractal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.