Skip to content

Wrong document score of nested knn query #138011

@AlexanderOtt85

Description

@AlexanderOtt85

Elasticsearch Version

9.2.1

Installed Plugins

No response

Java Version

bundled

OS Version

docker-image = docker.elastic.co/elasticsearch/elasticsearch:9.2.1

Problem Description

For a nested knn query with score_mode = max the document score does not match the expected score. I would expect the document score = 0.5852207 which is the maximum score of the inner hit (see 'nested knn query').

The score is not the expected one when "index_options": {"type":"bbq_disk"} is used. However, when "index_options": {"type":"hnsw"} is used, the score is the expected maximum from the inner_hits.

bbq_disk

"hits": { "total": { "value": 1, "relation": "eq" }, **"max_score": 0.57664675,** "hits": [ { ... **"_score": 0.57664675,** ..., "_explanation": { "value": 0.57664675, "description": "Score based on 1 child docs in range from 0 to 377, using score mode Max", "details": [ { "value": 0.57664675, "description": "sum of:", "details": [ { "value": 0.57664675, "description": "within top k documents", "details": [] }, { "value": 0.0, "description": "match on required clause, product of:", "details": [ { "value": 0.0, "description": "# clause", "details": [] }, { "value": 1.0, "description": "_nested_path:du.medium.keyframe_tc_hit", "details": [] } ] } ] } ] }, "inner_hits": { "du.medium.keyframe_tc_hit": { "hits": { "total": { "value": 352, "relation": "eq" }, **"max_score": 0.5852207,** ...

hnsw

"hits": { "total": { "value": 1, "relation": "eq" }, **"max_score": 0.5852207,** "hits": [ { ... **"_score": 0.5852207,** ... "_explanation": { "value": 0.5852207, "description": "Score based on 1 child docs in range from 0 to 377, using score mode Max", "details": [ { "value": 0.5852207, "description": "sum of:", "details": [ { "value": 0.5852207, "description": "within top 1 docs", "details": [] }, { "value": 0.0, "description": "match on required clause, product of:", "details": [ { "value": 0.0, "description": "# clause", "details": [] }, { "value": 1.0, "description": "_nested_path:du.medium.keyframe_tc_hit", "details": [] } ] } ] } ] }, "inner_hits": { "du.medium.keyframe_tc_hit": { "hits": { "total": { "value": 352, "relation": "eq" }, **"max_score": 0.5852207**, ...

Steps to Reproduce

  1. Create index
  2. Index document
  3. knnQuery where the score is not OK. expected score = 0.5852207 current score = 0.5711336

create_index.txt
index_document.txt
nested_query.txt

Logs (if relevant)

No response

Metadata

Metadata

Assignees

Labels

:Search Relevance/RankingScoring, rescoring, rank evaluation.>bugTeam:Search RelevanceMeta label for the Search Relevance team in Elasticsearchpriority:normalA label for assessing bug priority to be used by ES engineers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions