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
Add scoring support to percolate api #3506
Comments
Just in case someone comes across this (it's one of the few percolate examples showing up on google) and tries to get it to work, the percolate request needs a string or array in the sort field, not a boolean.
|
Confirming @zoellner, I had to use the following for my more complex filtered query: {
"query": {
"filtered": {
"filter": {
"term": {
"tenant_id": 29
}
},
"query": {
"function_score": {
"query": {"match_all": {}},
"functions": [
{
"script_score": {
"script": "doc[\"priority\"].value",
"lang": "expression"
}
}
]
}
}
}
},
"sort": "_score",
"size": 10
} note the escaped quotes; the single quotes did not work for me, they gave an exception:
|
Adding scoring support will allow the percolate matches to be sorted, or just assign a scores to percolate matches. Sorting by score can be very useful when millions of matches are being returned.
The scoring support hooks in into the percolate query option and adds two new boolean options:
sort
- Whether to sort the matches based on the score. This will also include the score for each match. Thesize
option is a required option when sorting percolate matches is enabled.score
- Whether to compute the score and include it with each match. This will not sort the matches.For both new options the
query
option needs to be specified, which is used to produce the scores. Thequery
option is normally used to control which percolate queries are evaluated. In order to give meaning to these score, the recently addedfunction_score
query in #3423 can be used to wrap these queries as is shown in the examples below.Examples
Indexing dummy percolator queries:
First query:
Second query:
These queries have two extra fields: 'priority' and 'create_date'. These fields can be used in the percolate api during sorting.
Script score example
Percolate request using the
script_score
function:Response:
Decay function example
Percolate request using the
exp
decay function:Response:
The text was updated successfully, but these errors were encountered: