diff --git a/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java b/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java index be77df42cb9..a44ade8d153 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java @@ -24,6 +24,7 @@ import java.io.Closeable; import java.io.IOException; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.Collections.unmodifiableMap; @@ -106,8 +107,9 @@ public final class IndexAnalyzers implements Closeable { @Override public void close() throws IOException { - IOUtils.close(() -> Stream.concat(analyzers.values().stream(), normalizers.values().stream()) - .filter(a -> a.scope() == AnalyzerScope.INDEX) - .iterator()); + IOUtils.close(Stream.of(analyzers.values().stream(), normalizers.values().stream(), whitespaceNormalizers.values().stream()) + .flatMap(s -> s) + .filter(a -> a.scope() == AnalyzerScope.INDEX) + .collect(Collectors.toList())); } } diff --git a/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java b/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java index 4803ee7386b..6bd2112fca7 100644 --- a/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java +++ b/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.analysis; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.elasticsearch.test.ESTestCase; @@ -26,6 +28,7 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; public class IndexAnalyzersTests extends ESTestCase { @@ -77,4 +80,38 @@ public class IndexAnalyzersTests extends ESTestCase { } } + public void testClose() throws IOException { + + AtomicInteger closes = new AtomicInteger(0); + NamedAnalyzer a = new NamedAnalyzer("default", AnalyzerScope.INDEX, new WhitespaceAnalyzer()){ + @Override + public void close() { + super.close(); + closes.incrementAndGet(); + } + }; + + NamedAnalyzer n = new NamedAnalyzer("keyword_normalizer", AnalyzerScope.INDEX, new KeywordAnalyzer()){ + @Override + public void close() { + super.close(); + closes.incrementAndGet(); + } + }; + + NamedAnalyzer w = new NamedAnalyzer("whitespace_normalizer", AnalyzerScope.INDEX, new WhitespaceAnalyzer()){ + @Override + public void close() { + super.close(); + closes.incrementAndGet(); + } + }; + + IndexAnalyzers ia = new IndexAnalyzers(Collections.singletonMap("default", a), + Collections.singletonMap("n", n), Collections.singletonMap("w", w)); + ia.close(); + assertEquals(3, closes.get()); + + } + }