From 43e54c0833dc6e7ecccf92e9c4ee8a8f1e434d3c Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Wed, 18 Dec 2024 13:00:24 -0500 Subject: [PATCH] Fix query timeout handling by checking searchContext.isSearchTimedOut() Signed-off-by: Andriy Redko --- .../opensearch/search/internal/ContextIndexSearcher.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java index aa8212e8dad69..a0c7432bd63f8 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -282,11 +282,20 @@ protected void search(List leaves, Weight weight, Collector c // reader order here. if (searchContext.shouldUseTimeSeriesDescSortOptimization()) { for (int i = leaves.size() - 1; i >= 0; i--) { + // If search is already flagged as timed out, do not continue searchLeaf(leaves.get(i), weight, collector); + // If search is already flagged as timed out, do not continue + if (searchContext.isSearchTimedOut()) { + return; + } } } else { for (int i = 0; i < leaves.size(); i++) { searchLeaf(leaves.get(i), weight, collector); + // If search is already flagged as timed out, do not continue + if (searchContext.isSearchTimedOut()) { + return; + } } } searchContext.bucketCollectorProcessor().processPostCollection(collector);