# Constant Score query Boost

**URL:** <https://discuss.elastic.co/t/constant-score-query-boost/17430>\
**Category:** Elasticsearch\
**Created:** [May 9, 2014, 12:35pm UTC](https://discuss.elastic.co/t/constant-score-query-boost/17430 "2014-05-09T12:35:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilija\_Subasic](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@Ilija\_Subasic](https://discuss.elastic.co/u/Ilija_Subasic)\
**Post date:** [May 9, 2014, 12:35pm UTC](https://discuss.elastic.co/t/constant-score-query-boost/17430/1 "2014-05-09T12:35:48Z")

</div>

My understanding of Constant Score Query in elasticsearch is that boost  
factor would be assigned as score for every matching query. The  
documentation[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html)  
says:

A query that wraps a filter or another query and simply returns a constant  
score equal to the query boost for every document in the filter.

However when I send this query:

"query": {  
"constant\_score": {  
"filter": {  
"term": {  
"source": "BBC"  
}  
},  
"boost": 3  
}  
},  
"fields": ["title", "source"]

all the matching documents are given a score of 1?! I cannot figure out  
what I am doing wrong, and had also tried with query instead of filter in  
constant\_score.

I've also tried using Function Score Query

"query": {  
"function\_score": {  
"query": {  
"term": {  
"source": "gdrive"  
}  
},  
"script\_score": {  
"script": "3"  
}  
}  
},  
"fields": [  
"title",  
"source"  
]

But the score is not set to 3, but to what seems to be the Lucene score for the document.

Any idea of what I am doing wrong?!

Thanks,

Ilija

--  
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/d1189650-a38c-4de3-8c06-b91d7703ee39%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1189650-a38c-4de3-8c06-b91d7703ee39%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [May 9, 2014, 1:04pm UTC](https://discuss.elastic.co/t/constant-score-query-boost/17430/2 "2014-05-09T13:04:57Z")

</div>

For the first one, you are probably experiencing score normalization  
happening. If you add explain: true to the query, it will tell you how it  
is being normalized.

For the second one, if you want the function\_score to totally override the  
Lucene score, you can "replace" the Lucene score with whatever comes out of  
the function\_score:

{  
"query": {  
"function\_score": {  
"query": {...}  
},  
"script\_score": {  
"script": "3"  
},  
"boost\_mode": "replace"  
}  
}  
}

--  
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/fc443609-1208-4412-bfdd-40a788f4a58a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fc443609-1208-4412-bfdd-40a788f4a58a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ilija\_Subasic](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@Ilija\_Subasic](https://discuss.elastic.co/u/Ilija_Subasic)\
**Post date:** [May 9, 2014, 1:40pm UTC](https://discuss.elastic.co/t/constant-score-query-boost/17430/3 "2014-05-09T13:40:15Z")

</div>

Ahh, thanks. Thought as much about the normalization. Can it be turned off  
anywhere except in the mapping?  
Function score works with boost\_mode=replace!

On Friday, May 9, 2014 3:04:57 PM UTC+2, Binh Ly wrote:

> For the first one, you are probably experiencing score normalization  
> happening. If you add explain: true to the query, it will tell you how it  
> is being normalized.
> 
> For the second one, if you want the function\_score to totally override the  
> Lucene score, you can "replace" the Lucene score with whatever comes out of  
> the function\_score:
> 
> {  
> "query": {  
> "function\_score": {  
> "query": {...}  
> },  
> "script\_score": {  
> "script": "3"  
> },  
> "boost\_mode": "replace"  
> }  
> }  
> }

--  
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/6c998b20-5db2-49f7-acfa-eb8569c28953%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6c998b20-5db2-49f7-acfa-eb8569c28953%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 5, 2017, 10:29pm UTC](https://discuss.elastic.co/t/constant-score-query-boost/17430/5 "2017-07-05T22:29:33Z")

</div>


