# Custom Filter Score

**URL:** <https://discuss.elastic.co/t/custom-filter-score/12938>\
**Category:** Elasticsearch\
**Created:** [July 25, 2013, 2:20pm UTC](https://discuss.elastic.co/t/custom-filter-score/12938 "2013-07-25T14:20:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shanmuthu83](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@shanmuthu83](https://discuss.elastic.co/u/shanmuthu83)\
**Post date:** [July 25, 2013, 2:20pm UTC](https://discuss.elastic.co/t/custom-filter-score/12938/1 "2013-07-25T14:20:06Z")

</div>

Hello All

Good Evening

i prepare custom\_filter\_score query script

_sample query_  
{  
"timeout" : 60000,  
"query" : {  
"custom\_filters\_score" : {  
"query" : {  
"bool" : {  
"should" : {  
"query\_string" : {  
"query" : "kids",  
"default\_operator" : "or"  
}  
},  
"minimum\_should\_match" : "1"  
}  
},  
"filters" : [ {  
"filter" : {  
"numeric\_range" : {  
"payload.calculate" : {  
"from" : "1",  
"to" : "4",  
"include\_lower" : false,  
"include\_upper" : false  
}  
}  
},  
"script" : "scoringFieldValueList =  
scoringFieldValue.split(delimiter); int i = 0; float \_cscore = \_score;  
while(i \<  
scoringFieldValueList.size()){if(\_source.payload.name.contains(scoringFieldValueList[i])){  
\_cscore = \_cscore + 1.5; } i++; } \_score=\_cscore;"  
}, {  
"filter" : {  
"numeric\_range" : {  
"payload.calculate" : {  
"from" : "1",  
"to" : "3",  
"include\_lower" : false,  
"include\_upper" : false  
}  
}  
},  
"script" : "scoringFieldValueList =  
scoringFieldValue.split(delimiter); int i = 0; _float \_cscore = \_score_;  
while(i \<  
scoringFieldValueList.size()){if(\_source.payload.name.contains(scoringFieldValueList[i])){  
\_cscore = \_cscore + 1.5; } i++; } \_score=\_cscore;"  
} ],  
"score\_mode" : "total",  
"params" : {  
"delimiter" : ",",  
"scoringFieldValue" : "American baby oil,American bandaid"  
}  
}  
},  
"explain" : false,  
"fields" : [ "payload.contractName", "payload.code",  
"payload.thing\_type", "payload.name", "payload.description",  
"payload.storefrontid" ]  
}

_es side throws the error_

Caused by: [Error: unresolvable property or identifier: \_score]  
[Near : {_float \_cscore = \_score_;}]

## please help me

Regards

_Shanmugam.M_

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [July 26, 2013, 9:58am UTC](https://discuss.elastic.co/t/custom-filter-score/12938/2 "2013-07-26T09:58:29Z")

</div>

Hi,  
the custom filters score query is meant to give a weight to different  
filters in order to influence the score of the main query when those  
filters match. You can either specify a boost associated to each filter, or  
a script. When using a script, you don't have the \_score of the main query  
available in the script, that's why you get that error.

On the other hand, the custom score query allows you to modify the score of  
a query by providing a script, where you do have the \_score of the query  
itself available.

The point is that with the custom score query you have the main query and a  
script that modifies its score, while with the custom filters score query  
you have a main query and different filters that don't modify the score of  
the main query but just influence it when matching. In fact the output of  
the script in the custom filters score is still a weight, not the score  
itself.

Hope this clarifies things for you

Cheers  
Luca

On Thursday, July 25, 2013 4:20:06 PM UTC+2, shanmugam wrote:

> Hello All
> 
> Good Evening
> 
> i prepare custom\_filter\_score query script
> 
> _sample query_  
> {  
> "timeout" : 60000,  
> "query" : {  
> "custom\_filters\_score" : {  
> "query" : {  
> "bool" : {  
> "should" : {  
> "query\_string" : {  
> "query" : "kids",  
> "default\_operator" : "or"  
> }  
> },  
> "minimum\_should\_match" : "1"  
> }  
> },  
> "filters" : [ {  
> "filter" : {  
> "numeric\_range" : {  
> "payload.calculate" : {  
> "from" : "1",  
> "to" : "4",  
> "include\_lower" : false,  
> "include\_upper" : false  
> }  
> }  
> },  
> "script" : "scoringFieldValueList =  
> scoringFieldValue.split(delimiter); int i = 0; float \_cscore = \_score;  
> while(i \<  
> scoringFieldValueList.size()){if(\_source.payload.name.contains(scoringFieldValueList[i])){  
> \_cscore = \_cscore + 1.5; } i++; } \_score=\_cscore;"  
> }, {  
> "filter" : {  
> "numeric\_range" : {  
> "payload.calculate" : {  
> "from" : "1",  
> "to" : "3",  
> "include\_lower" : false,  
> "include\_upper" : false  
> }  
> }  
> },  
> "script" : "scoringFieldValueList =  
> scoringFieldValue.split(delimiter); int i = 0; _float \_cscore = \_score_;  
> while(i \<  
> scoringFieldValueList.size()){if(\_source.payload.name.contains(scoringFieldValueList[i])){  
> \_cscore = \_cscore + 1.5; } i++; } \_score=\_cscore;"  
> } ],  
> "score\_mode" : "total",  
> "params" : {  
> "delimiter" : ",",  
> "scoringFieldValue" : "American baby oil,American bandaid"  
> }  
> }  
> },  
> "explain" : false,  
> "fields" : [ "payload.contractName", "payload.code",  
> "payload.thing\_type", "payload.name", "payload.description",  
> "payload.storefrontid" ]  
> }
> 
> _es side throws the error_
> 
> Caused by: [Error: unresolvable property or identifier: \_score]  
> [Near : {_float \_cscore = \_score_;}]
> 
> ## please help me
> 
> Regards
> 
> _Shanmugam.M_

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![shanmuthu83](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@shanmuthu83](https://discuss.elastic.co/u/shanmuthu83)\
**Post date:** [July 26, 2013, 3:10pm UTC](https://discuss.elastic.co/t/custom-filter-score/12938/3 "2013-07-26T15:10:28Z")

</div>

Thanks for ur reply

On Fri, Jul 26, 2013 at 3:28 PM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com) wrote:

> Hi,  
> the custom filters score query is meant to give a weight to different  
> filters in order to influence the score of the main query when those  
> filters match. You can either specify a boost associated to each filter, or  
> a script. When using a script, you don't have the \_score of the main query  
> available in the script, that's why you get that error.
> 
> On the other hand, the custom score query allows you to modify the score  
> of a query by providing a script, where you do have the \_score of the query  
> itself available.
> 
> The point is that with the custom score query you have the main query and  
> a script that modifies its score, while with the custom filters score query  
> you have a main query and different filters that don't modify the score of  
> the main query but just influence it when matching. In fact the output of  
> the script in the custom filters score is still a weight, not the score  
> itself.
> 
> Hope this clarifies things for you
> 
> Cheers  
> Luca
> 
> On Thursday, July 25, 2013 4:20:06 PM UTC+2, shanmugam wrote:
> 
> > Hello All
> > 
> > Good Evening
> > 
> > i prepare custom\_filter\_score query script
> > 
> > _sample query_  
> > {  
> > "timeout" : 60000,  
> > "query" : {  
> > "custom\_filters\_score" : {  
> > "query" : {  
> > "bool" : {  
> > "should" : {  
> > "query\_string" : {  
> > "query" : "kids",  
> > "default\_operator" : "or"  
> > }  
> > },  
> > "minimum\_should\_match" : "1"  
> > }  
> > },  
> > "filters" : [ {  
> > "filter" : {  
> > "numeric\_range" : {  
> > "payload.calculate" : {  
> > "from" : "1",  
> > "to" : "4",  
> > "include\_lower" : false,  
> > "include\_upper" : false  
> > }  
> > }  
> > },  
> > "script" : "scoringFieldValueList = scoringFieldValue.split(\*\*delimiter);  
> > int i = 0; float \_cscore = \_score; while(i \< scoringFieldValueList.size()){  
> > \*\*if(\_source.payload.name.\*\*contains(\*\*scoringFieldValueList[i])){  
> > \_cscore = \_cscore + 1.5; } i++; } \_score=\_cscore;"  
> > }, {  
> > "filter" : {  
> > "numeric\_range" : {  
> > "payload.calculate" : {  
> > "from" : "1",  
> > "to" : "3",  
> > "include\_lower" : false,  
> > "include\_upper" : false  
> > }  
> > }  
> > },  
> > "script" : "scoringFieldValueList = scoringFieldValue.split(\*\*delimiter);  
> > int i = 0; _float \_cscore = \_score_; while(i \<  
> > scoringFieldValueList.size()){\*\*if(\_source.payload.name.\*\*contains(\*\*scoringFieldValueList[i])){  
> > \_cscore = \_cscore + 1.5; } i++; } \_score=\_cscore;"  
> > } ],  
> > "score\_mode" : "total",  
> > "params" : {  
> > "delimiter" : ",",  
> > "scoringFieldValue" : "American baby oil,American bandaid"  
> > }  
> > }  
> > },  
> > "explain" : false,  
> > "fields" : [ "payload.contractName", "payload.code",  
> > "payload.thing\_type", "payload.name", "payload.description",  
> > "payload.storefrontid" ]  
> > }
> > 
> > _es side throws the error_
> > 
> > Caused by: [Error: unresolvable property or identifier: \_score]  
> > [Near : {_float \_cscore = \_score_;}]
> > 
> > ## please help me
> > 
> > Regards
> > 
> > _Shanmugam.M_
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Regards

_Shanmugam.M_

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:24am UTC](https://discuss.elastic.co/t/custom-filter-score/12938/4 "2017-07-06T02:24:18Z")

</div>


