# Custom\_filter\_score in 0.19.4 is not working fine

**URL:** https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838
**Category:** Elasticsearch
**Created:** [May 24, 2012, 9:35am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838 "2012-05-24T09:35:11Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)
#### Post date: [May 24, 2012, 9:35am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/1 "2012-05-24T09:35:11Z")

</div>

I just tried with different score\_mode in custom\_filter\_score, but its  
always returning the same score, and its always including the default  
scoring in the calculations, I just want to have the custom scoring to be  
used and not the calculation based score........

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [May 24, 2012, 9:39am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/2 "2012-05-24T09:39:13Z")

</div>

On Thu, 2012-05-24 at 02:35 -0700, Narinder Kaur wrote:

> I just tried with different score\_mode in custom\_filter\_score, but  
> its always returning the same score, and its always including the  
> default scoring in the calculations, I just want to have the custom  
> scoring to be used and not the calculation based score........

Without a gist showing what you're doing, your report is not useful.

Please see [Elastic Stack and Solutions Help · Forums and Slack | Elastic](http://www.elasticsearch.com/help)

ta

clint

---

<div class="post-metadata">

### Author: ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)
#### Post date: [May 24, 2012, 10:27am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/3 "2012-05-24T10:27:56Z")

</div>

{  
"query": {  
"custom\_filters\_score": {  
"query": {  
"match\_all": {}  
},  
"filters": [  
{  
"filter": {  
"range": {  
"guid": {  
"from": 0,  
"to": 1000  
}  
}  
},  
"boost": "3"  
},  
{  
"filter": {  
"range": {  
"guid": {  
"from": 1001,  
"to": 2000  
}  
}  
},  
"boost": "2"  
}  
],  
"score\_mode": "total"  
}  
}  
}

the result is :

hits: [

- {
  - \_shard: 0
  - \_node: kjfT2t0KTSulcTmlUKZEqA
  - \_index: es\_5
  - \_type: IzapGeoCity
  - \_id: 799
  - \_score: 3
  - \_source: {.....}
  - }]

and if I run this query :

{  
"query": {  
"custom\_filters\_score": {  
"query": {  
"term": {  
"title": "india"  
}  
},  
"filters": [  
{  
"filter": {  
"range": {  
"guid": {  
"from": 0,  
"to": 1000  
}  
}  
},  
"boost": "3"  
},  
{  
"filter": {  
"range": {  
"guid": {  
"from": 1001,  
"to": 2000  
}  
}  
},  
"boost": "2"  
}  
],  
"score\_mode": "total"  
}  
}  
}

the result is :

hits: [

- {
  - \_index: es\_5
  - \_type: IzapGeoCountry
  - \_id: 683
  - \_score: 26.04883
  - \_source: {....
  - }
  - ]

- here how the score can be 26.04883, when I am just assigning the  
values in custom\_filter\_score as "3" or "2".
- so in case of score\_mode:"total", the max score should be "5" and not  
26.04883.

surely, I know its including the default scoring in it for calculating the  
total score, but I just want the score that I assigned.

and when i tried with different score\_mode as "total", "first", "avg", in  
all cases the max score is 26.04883

Please tell me the solution for this...

Thanks

On Thursday, 24 May 2012 15:09:13 UTC+5:30, Clinton Gormley wrote:

> On Thu, 2012-05-24 at 02:35 -0700, Narinder Kaur wrote:
> 
> > I just tried with different score\_mode in custom\_filter\_score, but  
> > its always returning the same score, and its always including the  
> > default scoring in the calculations, I just want to have the custom  
> > scoring to be used and not the calculation based score........
> 
> Without a gist showing what you're doing, your report is not useful.
> 
> Please see [Elastic Stack and Solutions Help · Forums and Slack | Elastic](http://www.elasticsearch.com/help)
> 
> ta
> 
> clint

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [May 24, 2012, 10:51am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/4 "2012-05-24T10:51:48Z")

</div>

> ```
> * 
> * here how the score can be 26.04883, when I am just assigning
> the values in custom_filter_score as "3" or "2".
> * so in case of score_mode:"total", the max score should be "5"
> and not 26.04883.
> 
> ```

The custom\_filters\_score ALTERS your score, it doesn't override it  
completely. So it is a useful way of (eg) boosting recent documents over  
older documents while still retaining the 'relevance' factor.

You are doing a term QUERY, which means that ES looks to see how  
relevant the term 'india' is, based on all the terms in your index.  
That relevance score is then combined with your custom\_filters boost to  
produce a new value.

If you were to use a constant\_score query with a term FILTER, or a  
filtered query where the query is match\_all, and your filter is the term  
filter, then the \_score from the query part would be 1 (plus your query  
would be more efficient as you skip the relevance scoring step).

clint

---

<div class="post-metadata">

### Author: ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)
#### Post date: [May 24, 2012, 11:15am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/5 "2012-05-24T11:15:04Z")

</div>

But the same query was working fine with the earlier version of  
0.18!!!!!!!!!!

why was then it overriding the relevance score????

On Thursday, 24 May 2012 16:21:48 UTC+5:30, Clinton Gormley wrote:

> > ```
> > * 
> > * here how the score can be 26.04883, when I am just assigning 
> > the values in custom_filter_score as "3" or "2". 
> > * so in case of score_mode:"total", the max score should be "5" 
> > and not 26.04883. 
> > 
> > ```
> 
> The custom\_filters\_score ALTERS your score, it doesn't override it  
> completely. So it is a useful way of (eg) boosting recent documents over  
> older documents while still retaining the 'relevance' factor.
> 
> You are doing a term QUERY, which means that ES looks to see how  
> relevant the term 'india' is, based on all the terms in your index.  
> That relevance score is then combined with your custom\_filters boost to  
> produce a new value.
> 
> If you were to use a constant\_score query with a term FILTER, or a  
> filtered query where the query is match\_all, and your filter is the term  
> filter, then the \_score from the query part would be 1 (plus your query  
> would be more efficient as you skip the relevance scoring step).
> 
> clint

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [May 24, 2012, 11:57am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/6 "2012-05-24T11:57:58Z")

</div>

On Thu, 2012-05-24 at 04:15 -0700, Narinder Kaur wrote:

> But the same query was working fine with the earlier version of  
> 0.18!!!!!!!!!!
> 
> why was then it overriding the relevance score????

Not correct. I've tried on 0.19.3 and 0.17.8 and I get the same result,  
eg: [gist:2781011 · GitHub](https://gist.github.com/2781011)

You might have thought that it was working in a different way, but I  
don't see any difference between the two.

Just switch to using a term filter instead of a query, and it will work  
the way you expect.

clint

---

<div class="post-metadata">

### Author: ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)
#### Post date: [May 25, 2012, 8:35am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/7 "2012-05-25T08:35:34Z")

</div>

I just got the issue solved, I tried the same query with the constant\_score  
query and now its working fine. thanks for the guidance, cause of your  
comments, i could understand the logic behind this... thanks

On Thursday, 24 May 2012 17:27:58 UTC+5:30, Clinton Gormley wrote:

> On Thu, 2012-05-24 at 04:15 -0700, Narinder Kaur wrote:
> 
> > But the same query was working fine with the earlier version of  
> > 0.18!!!!!!!!!!
> > 
> > why was then it overriding the relevance score????
> 
> Not correct. I've tried on 0.19.3 and 0.17.8 and I get the same result,  
> eg: [gist:2781011 · GitHub](https://gist.github.com/2781011)
> 
> You might have thought that it was working in a different way, but I  
> don't see any difference between the two.
> 
> Just switch to using a term filter instead of a query, and it will work  
> the way you expect.
> 
> clint

---

<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, 3:27am UTC](https://discuss.elastic.co/t/custom-filter-score-in-0-19-4-is-not-working-fine/7838/8 "2017-07-06T03:27:09Z")

</div>


