diff --git a/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java b/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java index e80d006ea72..11ce914fff3 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java +++ b/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java @@ -63,6 +63,16 @@ public class ContextIndexSearcher extends IndexSearcher implements Releasable { this.dfSource = dfSource; } + @Override + public Query rewrite(Query original) throws IOException { + try { + return in.rewrite(original); + } catch (Throwable t) { + searchContext.clearReleasables(Lifetime.COLLECTION); + throw ExceptionsHelper.convertToElastic(t); + } + } + @Override public Weight createNormalizedWeight(Query query, boolean needsScores) throws IOException { try {