Skip to content

Fixed search_after for hybrid query - #1939

Merged
heemin32 merged 1 commit into
opensearch-project:mainfrom
martin-gaievski:fix/1934-hybrid-sort-search-after-nosuchelement
Aug 10, 2026
Merged

Fixed search_after for hybrid query#1939
heemin32 merged 1 commit into
opensearch-project:mainfrom
martin-gaievski:fix/1934-hybrid-sort-search-after-nosuchelement

Conversation

@martin-gaievski

Copy link
Copy Markdown
Member

Description

Added null check for topFieldDocs in scorecombiner for hybrid query, this avoids NPE when search_after and sort both are enabled.

Related Issues

Resolves #1934

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@martin-gaievski martin-gaievski added bug Something isn't working v3.9.0 labels Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 309a5d8)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@martin-gaievski
martin-gaievski force-pushed the fix/1934-hybrid-sort-search-after-nosuchelement branch from 94f7703 to 23cfff3 Compare August 8, 2026 22:49
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 23cfff3

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.43%. Comparing base (936d3c4) to head (309a5d8).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1939      +/-   ##
============================================
- Coverage     83.45%   83.43%   -0.02%     
- Complexity     3884     3885       +1     
============================================
  Files           291      291              
  Lines         13819    13821       +2     
  Branches       2294     2295       +1     
============================================
  Hits          11532    11532              
- Misses         1454     1456       +2     
  Partials        833      833              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Guard against NoSuchElementException in ScoreCombiner.getDocIdSortFieldsMap
when a shard returns no results for a hybrid query with sort/search_after.
An exhausted shard arrives with an empty top docs list but a non-zero total
hits count, which slipped past the totalHits==0 guard and hit getFirst() on
an empty list. Return early when the list is empty (behavior-equivalent: an
empty list iterates zero times and yields an empty map).

Adds a unit test that reproduces the crash before the fix and passes after.

Fixes opensearch-project#1934

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@martin-gaievski
martin-gaievski force-pushed the fix/1934-hybrid-sort-search-after-nosuchelement branch from 23cfff3 to 309a5d8 Compare August 9, 2026 00:41
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 309a5d8

@heemin32
heemin32 merged commit 33acce9 into opensearch-project:main Aug 10, 2026
145 of 221 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working v3.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hybrid query with sort + search_after throws bare NoSuchElementException (HTTP 500) once any shard is exhausted

3 participants