# ES7 Multiply scores from boolean queries

**URL:** https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130
**Category:** Elasticsearch
**Created:** [March 3, 2021, 2:56pm UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130 "2021-03-03T14:56:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![JF2018](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JF2018](https://discuss.elastic.co/u/JF2018)
#### Post date: [March 3, 2021, 2:56pm UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130/1 "2021-03-03T14:56:32Z")

</div>

Hey

Is it possible in some way to multiply the scores of two boolean queries?

I now BoolQuery.Should can add the scores together, but not multiply.  
Another possibility is function scores, but here I can only provide a filter, and not ie a boolQuery, so I can not use the score of the filter (since it is not scoring).  
I can use script\_score, but then I have to express my boolQuery in a script, and that is tricky.

Any help is appreciated  
/Jens

---

<div class="post-metadata">

### Author: ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)
#### Post date: [March 5, 2021, 10:20pm UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130/2 "2021-03-05T22:20:06Z")

</div>

No there is no way to multiply scores from two queries.  
We have not encountered a case where it would make sense to multiply scores.

---

<div class="post-metadata">

### Author: ![JF2018](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JF2018](https://discuss.elastic.co/u/JF2018)
#### Post date: [March 10, 2021, 8:15am UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130/3 "2021-03-10T08:15:32Z")

</div>

Hey Mayya, thanks for the answer!

My use case is that I wish to be able to use boolqueries as "building blocks" for my query.

Ie I have a base scoring algorithm, which I always use.

Together with my base scoring, I will make a possibility to multiply different factors to the scoring, depending on some different conditions.

I know I can do this using function score and filters, but then I cant use the scoring of the filter as part of the multiplier as I understands?

Since I cant use the score of the filter, I also have to make a filter for each condition I want to use, which can end up in a lot of filters - which seems to be quite slow.  
If I could use the score, I could instead build a boolQuery returning the factor I wish to multiply with.

And if I could multiply score of ie a should in a boolQuery, I wouldnt need any function scores applied at all

/Jens

---

<div class="post-metadata">

### Author: ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)
#### Post date: [March 10, 2021, 10:10pm UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130/4 "2021-03-10T22:10:12Z")

</div>

@JF2018 Thank you for providing your use case. I guess what I meant is that we have not encountered a case where it makes sense to multiply scores from two textual queries where meaningful scores are produced.

For all other cases, you can use `function_score` query with filters.

---

<div class="post-metadata">

### Author: ![JF2018](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JF2018](https://discuss.elastic.co/u/JF2018)
#### Post date: [March 10, 2021, 10:31pm UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130/5 "2021-03-10T22:31:11Z")

</div>

One case where it could be meaningful is if you ie use constant score query in you bool query.  
Den depending on which fields are available in the document, you can calculate a factor you wish to multiply the score with.

Instead of having multiple functions, I could use one bool query, building up the factor.

Another use case could be, if you have a custom similarity score on a field, and wish to use this value as a factor - and not the direct value of the field.

---

<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: [April 7, 2021, 10:31pm UTC](https://discuss.elastic.co/t/es7-multiply-scores-from-boolean-queries/266130/6 "2021-04-07T22:31:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
