Skip to content

fix: guard ranking script_score against zero-match segments (Lucene 10 NPE) - #33292

Merged
mohityadav766 merged 2 commits into
open-metadata:mainfrom
zhang-arvin:fix/issue-33167
Sep 15, 2026
Merged

mohityadav766 merged 2 commits into
open-metadata:mainfrom
zhang-arvin:fix/issue-33167

Conversation

@zhang-arvin

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #33167

On Lucene 10 (OpenSearch 3.3.x), a script_score whose inner query matches zero documents on a segment returns a null sub-scorer. DisjunctionMaxScorer → DisiWrapper → Objects.requireNonNull then throws an NPE. Combined with allow_partial_search_results=true (the default), the failing shard is silently dropped and the search endpoint returns HTTP 200 with hits.total.value = 0 even though the matching document exists.

The ranking matchers (ranking:fuzzyName, ranking:partialName, ranking:structuralContext, ranking:descriptionContext) all go through scriptScoreQuery, so every text ranking stage is exposed.

Fix

Wrap the inner query of scriptScoreQuery in a single-clause bool[should, minimumShouldMatch=1]. A zero-match segment then yields a well-defined empty iterator instead of null, so no scorer ever sees a null sub-iterator.

Scoring is unchanged: a single-clause bool with no must/filter scores exactly its clause, and the _name/matched_queries behavior the Ranking Details panel reads is preserved (the query name lives on the inner multi_match, inside the wrapper).

Applied to both OpenSearchQueryBuilder and ElasticQueryBuilder (issue only observed on Lucene 10 / OpenSearch 3.3.2, but the guard is harmless and symmetric on ES).

Type of change:

  • Bug fix

Notes:

  • Existing tests (SearchSourceBuilderFactoryTest) assert on the saturation script and stage query names, both preserved inside the wrapper — no test shape changes.
  • Please add the safe-to-test label to run CI on this fork PR.

…0 NPE)

On Lucene 10 (OpenSearch 3.x), a script_score whose inner query matches
zero documents on a segment returns a null sub-scorer, which
DisjunctionMaxScorer/DisiWrapper rejects with a NullPointerException.
Wrapped in dis_max with allow_partial_search_results=true, the failing
shard is silently dropped and search returns 0 results even though the
matching document exists (open-metadata#33167).

Wrap the inner query in a single-clause bool[should, minimumShouldMatch=1]
so a zero-match segment yields a well-defined empty iterator instead of
null. Scoring is unchanged: a single-clause bool with no must/filter
scores exactly its clause.
@zhang-arvin
zhang-arvin requested a review from a team as a code owner September 15, 2026 03:47
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@harshach harshach added safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch labels Sep 15, 2026
@github-actions github-actions Bot removed the safe to test Add this label to run secure Github workflows on PRs label Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@gitar-bot

gitar-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Fixes a Lucene 10 NPE in script_score queries that return zero matches on a segment by wrapping the inner query in a single-clause bool[should] to yield a well-defined empty iterator. The fix is applied to both OpenSearch and Elasticsearch query builders, preserves scoring and _name behavior, and requires no test changes. No issues found.

Review coverage

Rules No rules evaluated

Functional validation Not enabled · Set up

Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@mohityadav766 mohityadav766 added the safe to test Add this label to run secure Github workflows on PRs label Sep 15, 2026
@mohityadav766
mohityadav766 added this pull request to the merge queue Sep 15, 2026
Merged via the queue into open-metadata:main with commit 38cbdf9 Sep 15, 2026
191 of 202 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 1.13 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.0 opened as #33317 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 1.13 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

mohityadav766 added a commit that referenced this pull request Sep 15, 2026
…0 NPE) (#33292) (#33317)

On Lucene 10 (OpenSearch 3.x), a script_score whose inner query matches
zero documents on a segment returns a null sub-scorer, which
DisjunctionMaxScorer/DisiWrapper rejects with a NullPointerException.
Wrapped in dis_max with allow_partial_search_results=true, the failing
shard is silently dropped and search returns 0 results even though the
matching document exists (#33167).

Wrap the inner query in a single-clause bool[should, minimumShouldMatch=1]
so a zero-match segment yields a well-defined empty iterator instead of
null. Scoring is unchanged: a single-clause bool with no must/filter
scores exactly its clause.


(cherry picked from commit 38cbdf9)

Co-authored-by: Arvin <[email protected]>
Co-authored-by: Sriharsha Chintalapani <[email protected]>
Co-authored-by: Mohit Yadav <[email protected]>

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search returns 0 results (silent shard NPE) on Open Metadata 2.0.1 / OpenSearch 3.3.2 / Lucene 10: script_score inside dis_max yields null sub-scorer

3 participants