Skip to content

Commit bb0dff0

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

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
@@ -448,7 +448,7 @@ public boolean canApproximate(SearchContext context) {
448448
if (context.from() + context.size() == 0) {
449449
this.setSize(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO);
450450
} else {
451-
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
451+
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo() + 1));
452452
}
453453
if (context.request() != null && context.request().source() != null) {
454454
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());
@@ -467,6 +467,7 @@ public boolean canApproximate(SearchContext context) {
467467
}
468468
this.setSortOrder(primarySortField.order());
469469
}
470+
return context.request().source().terminateAfter() == SearchContext.DEFAULT_TERMINATE_AFTER;
470471
}
471472
return true;
472473
}

0 commit comments

Comments
 (0)