Skip to content

Fix SimpleSearchIT.doTestSimpleTerminateAfterTrackTotalHitsUpTo flaky test #18235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,14 @@ public void testSimpleTerminateAfterTrackTotalHitsUpToRandomSize0() throws Excep
doTestSimpleTerminateAfterTrackTotalHitsUpTo(0);
}

public void testSimpleTerminateAfterTrackTotalHitsUpToSize() throws Exception {
doTestSimpleTerminateAfterTrackTotalHitsUpTo(randomIntBetween(1, 29));
// Tests scenario where size <= track_total_hits_up_to (5)
public void testSimpleTerminateAfterTrackTotalHitsUpToSmallSize() throws Exception {
doTestSimpleTerminateAfterTrackTotalHitsUpTo(randomIntBetween(1, 5));
}

// Tests scenario where size > track_total_hits_up_to (5)
public void testSimpleTerminateAfterTrackTotalHitsUpToLargeSize() throws Exception {
doTestSimpleTerminateAfterTrackTotalHitsUpTo(randomIntBetween(6, 29));
}

public void testSimpleIndexSortEarlyTerminate() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ public boolean canApproximate(SearchContext context) {
if (context.from() + context.size() == 0) {
this.setSize(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO);
} else {
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
// We add +1 to ensure we collect at least one more document than required. This guarantees correct relation value:
// - If we find exactly trackTotalHitsUpTo docs: relation = EQUAL_TO
// - If we find > trackTotalHitsUpTo docs: relation = GREATER_THAN_OR_EQUAL_TO
// With +1, we will consistently get GREATER_THAN_OR_EQUAL_TO relation.
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()) + 1);
}
if (context.request() != null && context.request().source() != null) {
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());
Expand Down
Loading