-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Painless Context Doc: Add filter context example #35305
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,43 @@ query to include and exclude documents. | |
|
|
||
| *API* | ||
|
|
||
| The standard <<painless-api-reference, Painless API>> is available. | ||
| The standard <<painless-api-reference, Painless API>> is available. | ||
|
|
||
| *Example* | ||
|
|
||
| To run this example, first follow the steps in | ||
| <<painless-context-examples, context examples>>. | ||
|
|
||
| This script finds all unsold documents that cost less than $18. | ||
|
|
||
| [source,Painless] | ||
| ---- | ||
| doc['sold'].value == false && doc['cost'].value < 18 | ||
| ---- | ||
|
|
||
| Defining cost as a script parameter enables the cost to be configured | ||
| in the script query request. For example, the following request finds | ||
| all available theatre seats for evening performances that are under $18. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd tweak this slightly to put the emphasis on parameterizing cost: Defining |
||
| [source,js] | ||
| ---- | ||
| GET evening/_search | ||
| { | ||
| "query": { | ||
| "bool" : { | ||
| "filter" : { | ||
| "script" : { | ||
| "script" : { | ||
| "source" : "doc['sold'].value == false && doc['cost'].value < params.cost", | ||
| "params" : { | ||
| "cost" : 18 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ---- | ||
| // CONSOLE | ||
| // TEST[skip: requires setup from other pages] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "allows to find", I'd just say "finds". Given the straightforwardness of the example, I'd just summarize the intent of the script, instead of repeating what the code says:
This script finds all unsold documents that cost less than $18.