# Passing value of Variables at runtime in Percolate API

**URL:** https://discuss.elastic.co/t/passing-value-of-variables-at-runtime-in-percolate-api/196433
**Category:** Elasticsearch
**Created:** [August 23, 2019, 3:33am UTC](https://discuss.elastic.co/t/passing-value-of-variables-at-runtime-in-percolate-api/196433 "2019-08-23T03:33:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nehacv](https://avatars.discourse-cdn.com/v4/letter/n/258eb7/32.png) [@nehacv](https://discuss.elastic.co/u/nehacv)
#### Post date: [August 23, 2019, 3:33am UTC](https://discuss.elastic.co/t/passing-value-of-variables-at-runtime-in-percolate-api/196433/1 "2019-08-23T03:33:43Z")

</div>

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  
}  
}

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 20, 2019, 3:34am UTC](https://discuss.elastic.co/t/passing-value-of-variables-at-runtime-in-percolate-api/196433/2 "2019-09-20T03:34:57Z")

</div>

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