Elasticsearch relevance score calculation

Hi there,
I am newbie to Elasticsearch and got lost on how ES calculates the relevance score for the query result.
I am using ES v 6.0 and by running the explain API as follows, i got nothing but the following

GET /myinde/doc/_explain
{
"query" : {
"match" : { "audoc.authlast" : "mark" }
}
}

{
"_index": "myindex",
"_type": "doc",
"_id": "_explain",
"_version": 5,
"result": "updated",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 16266195,
"_primary_term": 2
}

please, can you elaborate how is ES calculates the relevance score? and how to explain the relevance in the result above?

That's a little unfortunate. What you've done with that request is add a document to an index.
The correct URL for the explain API includes a doc ID on the end of the URL. This is missing from your URL so it has assumed _explain is an ID (underscores are legal prefixes for doc IDs but in an ideal world we wouldn't allow that).
Presumably you issued the command in Kibana Console and because browsers don't like sending bodies with GETs the request is silently converted into a POST to send the body.

So all of the above was converted into a request to index a document with a query field in the body. This may have unfortunately updated your index mapping too, introducing new fields.
The response is not an explanation of a match but a receipt for your newly created document.

Thank you Mark! yes, i have realized i have to pass explicit doc_id for the explain API later. unfortunately, the previous GET was indexed as a document as per your explanation.

I will need to modify the mapping index because it was updated. though i still not sure how relevancy works. below was the modified explain i did run. what i am confused about that first records with high score having authors with high frequencey (i.e. 7) and with special characters in their name (i.e. M'ark), while 5th/7th record in result having same frequency (7) and without special characters in their name. i thought the authors without special characters would show first (i.e. Mark)!!

GET /evcafereindex2/author/aut_M64d649f815d2e14138dM725110178163220/_explain
{

  "query" : {

    "match" : { "audoc.authlast": {"query": "mark" }}

  }

}

result

{
"_index": "myindex",
"_type": "author",
"_id": "123",
"matched": true,
"explanation": {
"value": 14.357386,
"description": "sum of:",
"details": [
{
"value": 14.357386,
"description": "weight(audoc.authlast:mark in 127662) [PerFieldSimilarity], result of:",
"details": [
{
"value": 14.357386,
"description": "score(doc=127662,freq=7.0 = termFreq=7.0\n), product of:",
"details": [
{
"value": 9.65505,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 150,
"description": "docFreq",
"details":
},
{
"value": 2347855,
"description": "docCount",
"details":
}
]
},
{
"value": 1.4870337,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 7,
"description": "termFreq=7.0",
"details":
},
{
"value": 1.2,
"description": "parameter k1",
"details":
},
{
"value": 0.75,
"description": "parameter b",
"details":
},
{
"value": 2.094112,
"description": "avgFieldLength",
"details":
},
{
"value": 7.111111,
"description": "fieldLength",
"details":
}
]
}
]
}
]
},
{
"value": 0,
"description": "match on required clause, product of:",
"details": [
{
"value": 0,
"description": "# clause",
"details":
},
{
"value": 1,
"description": "_type:author",
"details":
}
]
}
]
}
}

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