# Set score vs. Boost score

**URL:** <https://discuss.elastic.co/t/set-score-vs-boost-score/6503>\
**Category:** Elasticsearch\
**Created:** [January 25, 2012, 9:27pm UTC](https://discuss.elastic.co/t/set-score-vs-boost-score/6503 "2012-01-25T21:27:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)\
**Post date:** [January 25, 2012, 9:27pm UTC](https://discuss.elastic.co/t/set-score-vs-boost-score/6503/1 "2012-01-25T21:27:47Z")

</div>

Hi,

I want to create a script that boosts the scores of documents by a  
computed amount. I want to boost the score, not replace it.

The code I tried looks like this (qb is a QueryBuilder built by  
earlier code):

qb = new CustomScoreQueryBuilder(qb)  
.lang("mvel")  
.script("2");

The expected result is that this would multiply all the scores of the  
results by 2. (I realize there are better ways to multiply by 2, but I  
intend to replace the 2 with a more complex formula once I know it  
works).

What happens, instead, is that all the scores for all the hits are set  
equal to 2.

If I could access the original score and multiply it myself, I would  
do so, but I tried using doc.score to access it and this didn't work  
at all.

How can I accomplish the desired result?

Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 25, 2012, 9:55pm UTC](https://discuss.elastic.co/t/set-score-vs-boost-score/6503/2 "2012-01-25T21:55:37Z")

</div>

Please don't send the same question twice.

The script should be "\_score \* 2".

On Wednesday, January 25, 2012 at 11:27 PM, Frank LaRosa wrote:

> Hi,
> 
> I want to create a script that boosts the scores of documents by a  
> computed amount. I want to boost the score, not replace it.
> 
> The code I tried looks like this (qb is a QueryBuilder built by  
> earlier code):
> 
> qb = new CustomScoreQueryBuilder(qb)  
> .lang("mvel")  
> .script("2");
> 
> The expected result is that this would multiply all the scores of the  
> results by 2. (I realize there are better ways to multiply by 2, but I  
> intend to replace the 2 with a more complex formula once I know it  
> works).
> 
> What happens, instead, is that all the scores for all the hits are set  
> equal to 2.
> 
> If I could access the original score and multiply it myself, I would  
> do so, but I tried using doc.score to access it and this didn't work  
> at all.
> 
> How can I accomplish the desired result?
> 
> Thanks.

---

<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:41am UTC](https://discuss.elastic.co/t/set-score-vs-boost-score/6503/3 "2017-07-06T03:41:26Z")

</div>


