Skip to content

Fixing for NPE when there is no query specified for the standard retriever#142479

Merged
pmpailis merged 10 commits intoelastic:mainfrom
pmpailis:fix_for_npe_in_standard_retriever_when_no_query
Feb 16, 2026
Merged

Fixing for NPE when there is no query specified for the standard retriever#142479
pmpailis merged 10 commits intoelastic:mainfrom
pmpailis:fix_for_npe_in_standard_retriever_when_no_query

Conversation

@pmpailis
Copy link
Contributor

@pmpailis pmpailis commented Feb 13, 2026

query parameter for a standard retriever is optional as per the documentation.

However, it is possible to run to an NPE when using an "empty" standard retriever within a compound retriever like rrf or linear, as there is no guard against null values when computing topDocsQuery (in contrast to what we do in other methods).

In this PR, we assume that an empty/null body equals to a MatchAllDocsQuery (as in standard search API) and capture that only for topDocsQuery. There were a couple of other options visited, like handling this on rewrite, or returning null, but the scope of the fix was changing significantly (e.g. we would also have to update all consumers of topDocsQuery including RuleQueryBuilder) so this seemed like the most constrained, yet sufficient, solution. Happy to discuss more on this though.

Closes #142336

@pmpailis pmpailis added >bug :Search Relevance/Ranking Scoring, rescoring, rank evaluation. auto-backport Automatically create backport pull requests when merged v9.3.1 v8.19.12 v9.2.6 labels Feb 13, 2026
@elasticsearchmachine elasticsearchmachine added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.4.0 labels Feb 13, 2026
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@iverase iverase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it was just that, nice. LGTM

Copy link
Contributor

@ioanatia ioanatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes make sense to me.
consider that this is already valid and executes a match all:

GET wikipedia/_search
{
    "retriever": {
        "standard": {
        }
    }
}

I don't see why it shouldn't be supported when using empty standard retrievers in compound retrievers.

- match: { hits.hits.1.fields.keyword.0: "keyword" }

---
"rrf retriever with a standard retriever with no query but a sort":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a NodeFeature here for bwc tests? I think only for these tests, since for the one in 10_standard_retriever.yml that should already work on main and previous versions (we just did not have a test for it yet).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Added in 5294f8b

@pmpailis pmpailis merged commit c1f55f2 into elastic:main Feb 16, 2026
35 checks passed
pmpailis added a commit to pmpailis/elasticsearch that referenced this pull request Feb 16, 2026
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.3
8.19 Commit could not be cherrypicked due to conflicts
9.2

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 142479

pmpailis added a commit to pmpailis/elasticsearch that referenced this pull request Feb 16, 2026
pmpailis added a commit to pmpailis/elasticsearch that referenced this pull request Feb 16, 2026
…iever (elastic#142479)

(cherry picked from commit c1f55f2)

# Conflicts:
#	x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/RankRRFFeatures.java
@pmpailis
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Questions ?

Please refer to the Backport tool documentation

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

Labels

auto-backport Automatically create backport pull requests when merged backport pending >bug :Search Relevance/Ranking Scoring, rescoring, rank evaluation. Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v8.19.12 v9.2.6 v9.3.1 v9.4.0

4 participants