Skip to content
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

Make sure processPostCollection is called in case of early termination #14208

Merged
merged 1 commit into from
Jun 12, 2024
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 @@ -187,4 +187,27 @@ public void testAggsOnEmptyShards() {
// Validate non-global agg does not throw an exception
assertSearchResponse(client().prepareSearch("idx").addAggregation(stats("value_stats").field("score")).get());
}

public void testAggsWithTerminateAfter() throws InterruptedException {
assertAcked(
prepareCreate(
"terminate_index",
Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
).setMapping("f", "type=keyword").get()
);
List<IndexRequestBuilder> docs = new ArrayList<>();
for (int i = 0; i < randomIntBetween(5, 20); ++i) {
docs.add(client().prepareIndex("terminate_index").setSource("f", Integer.toString(i / 3)));
}
indexRandom(true, docs);

SearchResponse response = client().prepareSearch("terminate_index")
.setSize(2)
.setTerminateAfter(1)
.addAggregation(terms("f").field("f"))
.get();
assertSearchResponse(response);
assertTrue(response.isTerminatedEarly());
assertEquals(response.getHits().getHits().length, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ private static boolean searchWithCollector(
try {
searcher.search(query, queryCollector);
} catch (EarlyTerminatingCollector.EarlyTerminationException e) {
// EarlyTerminationException is not caught in ContextIndexSearcher to allow force termination of collection. Postcollection
// still needs to be processed for Aggregations when early termination takes place.
searchContext.bucketCollectorProcessor().processPostCollection(queryCollector);
queryResult.terminatedEarly(true);
}
if (searchContext.isSearchTimedOut()) {
Expand Down
Loading