Elasticsearch scoring Issue for same data

I have an Elastic Index with the below 4 documents.

PUT test/_doc/1
{
"tag" : "prove"
}
PUT test/_doc/2
{
"tag" : "prove"
}
PUT test/_doc/3
{
"tag" : "freckle"
}
PUT test/_doc/4
{
"tag" : "freckle"
}

On this i am running a simple query to pick the documents, with tag either prove or freckle. As one can infer all four will come in the results.

Query-

GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "tag": "prove freckle"
          }
        }
      ]
    }
  }
}

Result -

{
  "took" : 950,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : 0.87546873,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.87546873,
        "_source" : {
          "tag" : "freckle"
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 0.87546873,
        "_source" : {
          "tag" : "freckle"
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.53899646,
        "_source" : {
          "tag" : "prove"
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.53899646,
        "_source" : {
          "tag" : "prove"
        }
      }
    ]
  }
}

I am unable to understand how elastic is giving different scores to docs, although all documents match the query and all are in the same shard. No one has other fields, and all docs are equally unique, then how come such variation in result??
Why freckle tag doc is gaining more scores than prove?

The length of a term also plays a role.

You can add the "explain": true option to see how it's computed.

1 Like

If you have any deleted documents the words they used can still contribute to scores on surviving docs that are searched using these same terms.
The popularity count for a term can include deleted docs until they are eventually merged away.

2 Likes

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