Count maximum possible score for query


(Kn) #1

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?


(Christoph) #2

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 (second part)

Also:

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.


(Kn) #3

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.


(system) #4

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