Skip to content

Conversation

@carlosdelest
Copy link
Member

KNN function performs prefiltering, so for a query like:

FROM test
WHERE KNN(field, [0, 1, 2]) AND text: "value"

the KNN function will receive text: "value" as a prefilter:

FROM test
WHERE KNN(field, [0, 1, 2] <with text:"value" as prefilter>) AND text: "value"

However, text: "value" remains as part of the conjunction, so in the end it will be transformed into a boolean query for the KNN and MATCH function. And the problem is, that the MATCH function will be scored, so it will impact both performance and overall scoring.

Including a prefilter for KNN is equivalent to the conjunction itself, so we can safely remove the other side of the conjunction when there is a KNN function on the other side that includes it as prefilter.

This PR transforms the above expression into:

FROM test
WHERE KNN(field, [0, 1, 2] <with text:"value" as prefilter>)

so there is no need to generate a separate query for the MATCH function, and it is not combined for scoring purposes.

@carlosdelest carlosdelest added >enhancement Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch Team:Search - Relevance The Search organization Search Relevance team :Search Relevance/ES|QL Search functionality in ES|QL v9.3.0 labels Nov 19, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @carlosdelest, I've created a changelog YAML for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Search Relevance/ES|QL Search functionality in ES|QL Team:Search - Relevance The Search organization Search Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants