Passing value of Variables at runtime in Percolate API

I have some documents with type percolate, with queries defined in them. Each query has a custom script score. I want the script score to be configurable and have a variable which will be passed when searching for the document.

Can someone help how I can use variables in script score for percolate API and pass the value at runtime??

Sample:
The below search query throws syntax error.

PUT /my_index
{
"mappings": {
"properties": {
"location": {
"type": "keyword"
}
"query": {
"type": "percolator"
}
}
}
}






PUT /my_index/_doc/doc1?refresh
{
"query":{
"function_score":{
"query":{
"bool":{
"should": [
{
"match": {"location":"Paris"
}
}
]
}
},
"functions":[
{
"filter":{
"match": {"location":"Paris"
}
},
"script_score" : {
"script" : {
"lang": "painless",
"source" : "params.score1 * ((params.score2 * 10) + (params.score3 * {{params.runtime_score}}) + (params.score4 * 7))",
"params": {
"score1": 0.5,
"score2": 0.2,
"score3": 0.3,
"score4": 0.3
}
}
}
}
],
"boost_mode": "replace",
"score_mode":"sum",
"min_score" : 0
}
}
}






GET /my_index/_search
{
"query" : {
"percolate" : {
"field" : "query",
"document" : {
"location" : "Paris"
}
}
},
"params":{
"runtime_score": 6
}
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.