# Script in custom\_filters\_score/function\_score

**URL:** <https://discuss.elastic.co/t/script-in-custom-filters-score-function-score/19874>\
**Category:** Elasticsearch\
**Created:** [September 18, 2014, 9:32pm UTC](https://discuss.elastic.co/t/script-in-custom-filters-score-function-score/19874 "2014-09-18T21:32:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hieu\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@Hieu\_Nguyen](https://discuss.elastic.co/u/Hieu_Nguyen)\
**Post date:** [September 18, 2014, 9:32pm UTC](https://discuss.elastic.co/t/script-in-custom-filters-score-function-score/19874/1 "2014-09-18T21:32:45Z")

</div>

The documentation for custom\_filters\_score does not provide an example of  
how "script" can be used. However, it refers to function\_score in later  
versions of ES search, and the doc of function\_score has the following  
example:

"custom\_filters\_score": {  
"filters": [  
{  
"boost\_factor": "3",  
"filter": {...}  
},  
{  
"filter": {â.},  
"script": "\_score \* doc['my\_numeric\_field'].value / pow(param1, param2)"  
}  
],  
"params": {  
"param1": 2,  
"param2": 3.1  
},  
"query": {...},  
"score\_mode": "first"  
}

becomes:

"function\_score": {  
"functions": [  
{  
"boost\_factor": "3",  
"filter": {...}  
},  
{  
"filter": {...},  
"script\_score": {  
"params": {  
"param1": 2,  
"param2": 3.1  
},  
"script": "\_score \* doc['my\_numeric\_field'].value / pow(param1, param2)"  
}  
}  
],  
"query": {...},  
"score\_mode": "first"  
}

The script in the example seems to imply that the script will solely  
determine the score, but in practice the value evaluated by the script will  
be multiplied with the query score. So the script in the example should  
have been: "doc['my\_numeric\_field'].value / pow(param1, param2)"

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0bd7f0ec-8dd1-4200-8d6a-b00fa56b8131%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0bd7f0ec-8dd1-4200-8d6a-b00fa56b8131%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hieu\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@Hieu\_Nguyen](https://discuss.elastic.co/u/Hieu_Nguyen)\
**Post date:** [September 18, 2014, 9:42pm UTC](https://discuss.elastic.co/t/script-in-custom-filters-score-function-score/19874/2 "2014-09-18T21:42:14Z")

</div>

I guess at least for function\_score an alternative is to specify boost\_mode  
to "replace" instead of the default "multiply". But I don't think there is  
an equivalent alternative for custom\_filters\_score. In any case, I think  
the documentation should be updated or made clearer.

Thanks,  
Hieu

On Thursday, September 18, 2014 2:32:45 PM UTC-7, Hieu Nguyen wrote:

> The documentation for custom\_filters\_score does not provide an example of  
> how "script" can be used. However, it refers to function\_score in later  
> versions of ES search, and the doc of function\_score has the following  
> example:
> 
> "custom\_filters\_score": {  
> "filters": [  
> {  
> "boost\_factor": "3",  
> "filter": {...}  
> },  
> {  
> "filter": {â.},  
> "script": "\_score \* doc['my\_numeric\_field'].value / pow(param1, param2)"  
> }  
> ],  
> "params": {  
> "param1": 2,  
> "param2": 3.1  
> },  
> "query": {...},  
> "score\_mode": "first"  
> }
> 
> becomes:
> 
> "function\_score": {  
> "functions": [  
> {  
> "boost\_factor": "3",  
> "filter": {...}  
> },  
> {  
> "filter": {...},  
> "script\_score": {  
> "params": {  
> "param1": 2,  
> "param2": 3.1  
> },  
> "script": "\_score \* doc['my\_numeric\_field'].value / pow(param1, param2)"  
> }  
> }  
> ],  
> "query": {...},  
> "score\_mode": "first"  
> }
> 
> The script in the example seems to imply that the script will solely  
> determine the score, but in practice the value evaluated by the script will  
> be multiplied with the query score. So the script in the example should  
> have been: "doc['my\_numeric\_field'].value / pow(param1, param2)"

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5da25ff7-1162-44ee-8ae0-7b1c2501cd7a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5da25ff7-1162-44ee-8ae0-7b1c2501cd7a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:01am UTC](https://discuss.elastic.co/t/script-in-custom-filters-score-function-score/19874/3 "2017-07-06T01:01:11Z")

</div>


