# Function\_score weight of 0.0 returns 1

**URL:** <https://discuss.elastic.co/t/function-score-weight-of-0-0-returns-1/22344>\
**Category:** Elasticsearch\
**Created:** [February 24, 2015, 2:49am UTC](https://discuss.elastic.co/t/function-score-weight-of-0-0-returns-1/22344 "2015-02-24T02:49:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Steinmetz](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jeff\_Steinmetz](https://discuss.elastic.co/u/Jeff_Steinmetz)\
**Post date:** [February 24, 2015, 2:49am UTC](https://discuss.elastic.co/t/function-score-weight-of-0-0-returns-1/22344/1 "2015-02-24T02:49:59Z")

</div>

Any ideas why this would return a score of 1, when the last (bool must\_not)  
matches, even though the weight is set to 0.0?

As a bit of background, this provides custom scoring where

- if one field matches, score at .35,
- if another more important field matches, score .65,
- if both match, score 1.0 (the sume)
- if non match, score 0

If I change the no match weight to -1 or something very small, like  
0.000001, the weight for the must\_not match comes back accurately.  
I am thinking this is some kind of divide by 0 error handerl in ES, that  
returns 1 when a score hits 0?

GET test/document/\_search  
{  
"query": {  
"function\_score": {  
"filter": { "term": { "type": "animal" } },  
"functions": [  
{  
"filter": {  
"bool" : {  
"must" : {  
"term" : { "content" : "fish"}  
}}},  
"weight": 0.35  
},  
{  
"filter": {  
"bool" : {  
"must" : {  
"term" : { "user\_description" : "fish" }  
}}},  
"weight": 0.65  
},  
{  
"filter": {  
"bool" : {  
"must\_not" : [  
{"term" : { "user\_description" : "fish" }},  
{"term" : { "content" : "fish" }}  
]  
}  
},  
"weight": 0.0  
}  
],  
"score\_mode": "sum"  
}  
}  
}

--  
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/de18cc05-c797-45d5-aa4d-b5426e9562d7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de18cc05-c797-45d5-aa4d-b5426e9562d7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jeff\_Steinmetz](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jeff\_Steinmetz](https://discuss.elastic.co/u/Jeff_Steinmetz)\
**Post date:** [February 24, 2015, 2:59am UTC](https://discuss.elastic.co/t/function-score-weight-of-0-0-returns-1/22344/2 "2015-02-24T02:59:39Z")

</div>

BTW, I am running against Elasticsearch version  
1.4.4

On Monday, February 23, 2015 at 6:49:59 PM UTC-8, Jeff Steinmetz wrote:

> Any ideas why this would return a score of 1, when the last (bool  
> must\_not) matches, even though the weight is set to 0.0?
> 
> As a bit of background, this provides custom scoring where
> 
> - if one field matches, score at .35,
> - if another more important field matches, score .65,
> - if both match, score 1.0 (the sume)
> - if non match, score 0
> 
> If I change the no match weight to -1 or something very small, like  
> 0.000001, the weight for the must\_not match comes back accurately.  
> I am thinking this is some kind of divide by 0 error handerl in ES, that  
> returns 1 when a score hits 0?
> 
> GET test/document/\_search  
> {  
> "query": {  
> "function\_score": {  
> "filter": { "term": { "type": "animal" } },  
> "functions": [  
> {  
> "filter": {  
> "bool" : {  
> "must" : {  
> "term" : { "content" : "fish"}  
> }}},  
> "weight": 0.35  
> },  
> {  
> "filter": {  
> "bool" : {  
> "must" : {  
> "term" : { "user\_description" : "fish" }  
> }}},  
> "weight": 0.65  
> },  
> {  
> "filter": {  
> "bool" : {  
> "must\_not" : [  
> {"term" : { "user\_description" : "fish" }},  
> {"term" : { "content" : "fish" }}  
> ]  
> }  
> },  
> "weight": 0.0  
> }  
> ],  
> "score\_mode": "sum"  
> }  
> }  
> }

--  
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/7edb1ff9-a2f5-4770-9d83-d1afdd5af6ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7edb1ff9-a2f5-4770-9d83-d1afdd5af6ff%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, 12:30am UTC](https://discuss.elastic.co/t/function-score-weight-of-0-0-returns-1/22344/3 "2017-07-06T00:30:36Z")

</div>


