Skip to content

score_mode not working as expected in nested knn queriesΒ #122625

@nit0906

Description

@nit0906

Elasticsearch Version

8.17.2

Installed Plugins

No response

Java Version

21.0.5

OS Version

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

Problem Description

I am trying to do a nested knn query on a vector field. I am trying to use the score_mode option to have the top level document score be decided based on the inner hits scores.

However it looks like only the mode max is working not matter which mode I select. For instance, I have 2 document hits, each with 2 inner hits.

doc1 :
innerHit1: 0.9055939
innerHit2: 0.8818512

doc2:
innerHit1: 0.90008545
innerHit2: 0.89920044

Now, even if I select score_mode=avg/min/sum - the doc1 score is always 0.9063721 and doc2 score is always 0.8989563, which tends to indicate that only max score_mode is working.

However if I select score_mode = none, the doc scores are 0 - so that seems to be working.

This is the query that I am testing out -

{ "query": { "nested": { "path": "foo.bar", "score_mode": "sum", "inner_hits": {}, "query": { "knn": { "boost": 1, "field": "foo.bar.vector", "query_vector": [ -0.0109421825, -0.023024175, 0.0008527628, -0.00867597, -0.0038518896, .... ], "num_candidates": 3 } } } } }

Steps to Reproduce

steps_to_reproduce.txt

The file consists of index mapping, test documents to be ingested and query to reproduce the issue.

The resulting scores are as follows -

doc1 :
innerHit1: 0.9055939
innerHit2: 0.8818512

doc2:
innerHit1: 0.90008545
innerHit2: 0.89920044

and as explained in the description, the score for top level docs remain the same irrespective of the score_mode being chosen.

Logs (if relevant)

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions