Repository navigation
fix(elasticsearch): avoid NaN score when first hit score is zero - #2748
Open
skyzhao1223 wants to merge 1 commit into
Open
skyzhao1223 wants to merge 1 commit into
skyzhao1223 wants to merge 1 commit into
Conversation
parseSearchResult normalized every hit by the first hit's _score. When the first _score is 0 (constant-score/filter context, no ranking), 0/0 produces NaN for the first hit and Infinity for the rest, corrupting downstream sorting and threshold filtering. Fall back to the raw score when the first score is 0. Tests cover the zero-score (no NaN) and normal normalization cases; the zero-score test fails on the old code.
skyzhao1223
requested review from
N3kox,
fanlv,
hi-pender,
junwen-lee,
liuyunchao-1998,
lvxinyu-1117,
mrh997 and
shentongmartin
as code owners
August 26, 2026 09:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a NaN/Inf score bug in the Elasticsearch search store.
Problem
parseSearchResultnormalized every hit's score by the first hit's_score:When the first hit's
_scoreis0(e.g. constant-score or filter context with no ranking),0/0producesNaNfor the first hit andInffor the rest, corrupting downstream score-based sorting and threshold filtering.Fix
Fall back to the raw score when the first score is
0(there is nothing to normalize against):Tests
elasticsearch_searchstore_test.goadds:TestParseSearchResultZeroScore: zero scores produce no NaN (fails on old code).TestParseSearchResultNormalizesScore:[2,4,1]normalizes to[1,2,0.5].