Ace McCloud
Ace McCloud

Reputation: 711

Elastic search score discrepancy

I have only a single record in my elastic search cluster. It has the text "Foo Bar".

When I run the following query on the cluster, the score comes out to be 0.11506979 :

{
  "size" : 100,
  "query" : {
        "query_string" : {
          "query" : "foo bar"
        }
      } 

}

However, when I run the following query (notice the * after foo bar) on the cluster, the score comes out to be 0.9798734

{
  "size" : 100,
  "query" : {
        "query_string" : {
          "query" : "foo bar*"
        }
      } 
}

Why is the score more in case I add the * ? Isn't there only one document to match?

Upvotes: 1

Views: 101

Answers (2)

Ankur Goel
Ankur Goel

Reputation: 206

When you use wildcards like * the scoring is done using ConstantScore strategy which takes only boost and queryNorm into account . Hence the score changes . pass the param explain=true to see how your score is being calculated.

Upvotes: 1

dark_shadow
dark_shadow

Reputation: 3573

Why is the score more in case I add the * ?

The above * matches documents that have fields matching a wildcard expression (not analyzed). It matches any character sequence (including the empty one)

Isn't there only one document to match?

It depends on your index analyzer, how you are indexing your fields in a given document. If you are using default analyzer then ES will use a standard analyzer. To check exactly how your indexed data is getting stored internally in ES go through this.

Also, regarding the actual score you should be aware of internal mechanism which is used by ES for scoring docs. This will help you getting a better idea of scoring mechanism.

In case of any doubts feel free to ask further questions.

Thanks

Upvotes: 1

Related Questions