From 201217945fdcb667ad7b0f9b54f926485ccab3b7 Mon Sep 17 00:00:00 2001 From: Alex Benusovich Date: Fri, 26 Aug 2016 16:59:22 -0700 Subject: [PATCH] Fix IndexNotFoundException if an multi index search request had a concrete index followed by an add/remove concrete index. The code now properly adds/removes the index instead of throwing an exception. Closes #3839 --- .../metadata/IndexNameExpressionResolver.java | 18 ++++++++---------- .../WildcardExpressionResolverTests.java | 4 ++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index df53395fe27..6ecf7483d80 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -607,23 +607,21 @@ public class IndexNameExpressionResolver extends AbstractComponent { add = false; expression = expression.substring(1); } + if (result == null) { + // add all the previous ones... + result = new HashSet<>(expressions.subList(0, i)); + } if (!Regex.isSimpleMatchPattern(expression)) { if (!unavailableIgnoredOrExists(options, metaData, expression)) { throw infe(expression); } - if (result != null) { - if (add) { - result.add(expression); - } else { - result.remove(expression); - } + if (add) { + result.add(expression); + } else { + result.remove(expression); } continue; } - if (result == null) { - // add all the previous ones... - result = new HashSet<>(expressions.subList(0, i)); - } final IndexMetaData.State excludeState = excludeState(options); final Map matches = matches(metaData, expression); diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java index 744477d6722..01110e796e8 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java @@ -49,6 +49,10 @@ public class WildcardExpressionResolverTests extends ESTestCase { assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*", "kuku"))), equalTo(newHashSet("testXXX", "testXYY", "kuku"))); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY", "kuku"))); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("*", "-kuku"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); + assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "+testYYY"))), equalTo(newHashSet("testXXX", "testYYY"))); + assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "-testXXX"))).size(), equalTo(0)); + assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "+testY*"))), equalTo(newHashSet("testXXX", "testYYY"))); + assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "-testX*"))).size(), equalTo(0)); } public void testConvertWildcardsTests() {