Skip to content

Commit d00440e

Browse files
committed
Adjust assertion for suggestion result when search timed out
there are scenarios where the hits collection succeed, as well as aggs, but the suggest phase terminates early due to a timeout. In that case, partial results may be returned if allowed. We have an assertion that verifies that whenever suggestions are returned as part of a query search result, all of the other query results also include suggest results. That is not the case if there's a timeout. This commit adjusts such assertion accordingly. This issues surfaced thanks to a new testSuggestWithPartialResults tests added to SearchTimeoutIT.
1 parent 94bf12a commit d00440e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,13 @@ static ReducedQueryPhase reducedQueryPhase(
475475
}
476476

477477
if (hasSuggest) {
478-
assert result.suggest() != null;
479-
for (Suggestion<? extends Suggestion.Entry<? extends Suggestion.Entry.Option>> suggestion : result.suggest()) {
480-
groupedSuggestions.computeIfAbsent(suggestion.getName(), s -> new ArrayList<>()).add(suggestion);
481-
if (suggestion instanceof CompletionSuggestion completionSuggestion) {
482-
completionSuggestion.setShardIndex(result.getShardIndex());
478+
assert result.suggest() != null || result.searchTimedOut();
479+
if (result.suggest() != null) {
480+
for (Suggestion<? extends Suggestion.Entry<? extends Suggestion.Entry.Option>> suggestion : result.suggest()) {
481+
groupedSuggestions.computeIfAbsent(suggestion.getName(), s -> new ArrayList<>()).add(suggestion);
482+
if (suggestion instanceof CompletionSuggestion completionSuggestion) {
483+
completionSuggestion.setShardIndex(result.getShardIndex());
484+
}
483485
}
484486
}
485487
}

0 commit comments

Comments
 (0)