# Count maximum possible score for query

**URL:** https://discuss.elastic.co/t/count-maximum-possible-score-for-query/135689
**Category:** Elasticsearch
**Created:** [June 13, 2018, 10:43am UTC](https://discuss.elastic.co/t/count-maximum-possible-score-for-query/135689 "2018-06-13T10:43:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lastic/32/32326_2.png) [@lastic](https://discuss.elastic.co/u/lastic)
#### Post date: [June 13, 2018, 10:43am UTC](https://discuss.elastic.co/t/count-maximum-possible-score-for-query/135689/1 "2018-06-13T10:43:14Z")

</div>

Hello.  
Does it is possible to count theoretical possible score for query?  
I have query with a lot of 'shoulds' with different boost for each should.  
I see 2 possibilities :

- stupid : make doc which will always correspond for 100% shoulds in query and it will give me real max\_score
- elasticsearch script

I am using Elastic 5.4.

Could you help me?

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [June 15, 2018, 1:49pm UTC](https://discuss.elastic.co/t/count-maximum-possible-score-for-query/135689/2 "2018-06-15T13:49:27Z")

</div>

This is not easily doable in a traditional search system like the ones based on Lucene (like Elasticsearch, Solr etc...). Here are some reasons related to Lucene queries that also apply to Elasticsearch:

[https://wiki.apache.org/lucene-java/ScoresAsPercentages](https://wiki.apache.org/lucene-java/ScoresAsPercentages) (second part)

Also:

[http://grokbase.com/t/lucene/java-user/0859r5cys9/theoretical-maximum-score](http://grokbase.com/t/lucene/java-user/0859r5cys9/theoretical-maximum-score)

Even if possible, there is hardly any good reason to do so, but it would be interesting to learn about the motivation you are having to do this.

---

<div class="post-metadata">

### Author: ![lastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lastic/32/32326_2.png) [@lastic](https://discuss.elastic.co/u/lastic)
#### Post date: [June 15, 2018, 4:57pm UTC](https://discuss.elastic.co/t/count-maximum-possible-score-for-query/135689/3 "2018-06-15T16:57:13Z")

</div>

So. I've already made it.  
My task was to find people which corresponds to some offer and get percentage of how they meet the conditions.

Person 1 has attributes :

- country : Poland
- sex : male
- age : 20
- parents : [Adam, Kate]

Person 2:

- country : Germany
- sex : female
- age : 22
- parents : [Adolf, Emma]

Person 3:

- country : Norway
- sex : male
- age : 30
- parents : [George, Hannah]

Query :  
(don't look at syntax, it's changed for ORM which I use)

```
    $query = ES::raw()->search([
        "index" => "search_worker",
        "type" => "worker",
        "body" => [
            "size" => intval(env("WS_SUGGESTED_LIMIT")),
            "query" => [
                "bool" => [
                    "should" => [
                         "term" => [
                            "country" => [
                               "value" => 'Poland', 
                               "boost" => 1
                        ],
                         "term" => [
                            "sex" => [
                               "value" => 'male', 
                               "boost" => 1
                      ],
                         "term" => [
                            "age" => [
                               "value" => 24, 
                               "boost" => 1
                      ],
                         "term" => [
                            "parents" => [
                               "value" => 'George', 
                               "boost" => 0.5
                      ],
                         "term" => [
                            "parents" => [
                               "value" => 'Kate', 
                               "boost" => 0.5
                      ]
                   ];
                ]
            ]
        ]
    ]); 

```

So. Total score for this search is sum all boosts in query = 4.  
Person 1 has score 2.5  
Person 2 has score 0.  
Person 3 has score 1.5

Then simply  
(Person\_score/Max\_score)\*100  
P.ex. Person 1 meets the query in 62,5%.

Hope that you understand and ofc. waiting for better way to solve that, if exists.

---

<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 13, 2018, 4:57pm UTC](https://discuss.elastic.co/t/count-maximum-possible-score-for-query/135689/4 "2018-07-13T16:57:17Z")

</div>

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