-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Painless Context Doc: Add min should match example #35423
Merged
mayya-sharipova
merged 4 commits into
elastic:master
from
mayya-sharipova:painless-context-min-should-match-example
Nov 15, 2018
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
01e8616
Painless Context Doc: Add min should match example
mayya-sharipova 77b69ef
Address Deb's comments
mayya-sharipova ca14000
Merge branch 'master' into painless-context-min-should-match-example
mayya-sharipova 0d33418
Merge remote-tracking branch 'upstream/master' into painless-context-…
mayya-sharipova 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 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 |
---|---|---|
|
@@ -25,4 +25,52 @@ results. | |
|
||
*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>>. | ||
|
||
Imagine that you want to find seats to performances by your favorite | ||
actors. You have a list of favorite actors in mind, and you want | ||
to find performances where the cast includes at least a certain | ||
number of them. `terms_set` query with `minimum_should_match_script` | ||
is a way to accomplish this. To make the query request more configurable, | ||
you can define `min_actors_to_see` as a script parameter. | ||
|
||
To ensure that the parameter `min_actors_to_see` doesn't exceed | ||
the number of favorite actors, you can use `num_term`s to get | ||
the number of actors in the list and `Math.min` to get the lesser | ||
of the two. | ||
|
||
[source,Painless] | ||
---- | ||
Math.min(params['num_terms'], params['min_actors_to_see']) | ||
---- | ||
|
||
The following request finds seats to performances with at least | ||
two of the three specified actors. | ||
|
||
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. "The following request finds seats to performances with at least two of the three specified actors." |
||
[source,js] | ||
---- | ||
GET seats/_search | ||
{ | ||
"query" : { | ||
"terms_set": { | ||
"actors" : { | ||
"terms" : ["smith", "earns", "black"], | ||
"minimum_should_match_script": { | ||
"source": "Math.min(params['num_terms'], params['min_actors_to_see'])", | ||
"params" : { | ||
"min_actors_to_see" : 2 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
---- | ||
// CONSOLE | ||
// TEST[skip: requires setup from other pages] | ||
|
This file contains 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
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.
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.
I'd pare this down to: "To ensure that the minimum number of actors doesn't exceed the number of favorite actors, you can use
num_terms
to get the number of actors in the list andMath.min
to get the lesser of the two."