Skip to content

Commit a204d82

Browse files
Disable approximation when there is terminate after (#18018)
Signed-off-by: Harsha Vamsi Kalluri <[email protected]> (cherry picked from commit 8948c1f) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 661f665 commit a204d82

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public boolean canApproximate(SearchContext context) {
444444
if (context.from() + context.size() == 0) {
445445
this.setSize(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO);
446446
} else {
447-
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
447+
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo() + 1));
448448
}
449449
if (context.request() != null && context.request().source() != null) {
450450
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());
@@ -463,6 +463,7 @@ public boolean canApproximate(SearchContext context) {
463463
}
464464
this.setSortOrder(primarySortField.order());
465465
}
466+
return context.request().source().terminateAfter() == SearchContext.DEFAULT_TERMINATE_AFTER;
466467
}
467468
return true;
468469
}

0 commit comments

Comments
 (0)