Skip to content

Commit 57b5216

Browse files
maarab7javanna
authored andcommitted
Fix parameter value for calling data.advanceExact (#44205)
While the code works perfectly well for a single segment, it returns the wrong values for multiple segments. E.g. If we have 500 docs in one segment and if we want to get the doc id = 280 then data.advanceExact(topDocs.scoreDocs[i].doc) works fine. If we have two segments, say, with first segment having docs 1-200 and the second segment having docs 201-500, then 280 is fetched from the second segment but is actually 480. Subtracting the docBase (280-200) takes us to the correct document which is 80 in the second segment and actually 280.
1 parent b602549 commit 57b5216

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

plugins/examples/rescore/src/main/java/org/elasticsearch/example/rescore/ExampleRescoreBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext r
191191
}
192192
data = ((AtomicNumericFieldData) fd).getDoubleValues();
193193
}
194-
if (false == data.advanceExact(topDocs.scoreDocs[i].doc)) {
194+
if (false == data.advanceExact(topDocs.scoreDocs[i].doc - leaf.docBase)) {
195195
throw new IllegalArgumentException("document [" + topDocs.scoreDocs[i].doc
196196
+ "] does not have the field [" + context.factorField.getFieldName() + "]");
197197
}

0 commit comments

Comments
 (0)