diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 388dd7d75ca..efb8f871c73 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -671,6 +671,10 @@ public class MetaData implements Iterable { } boolean add = true; if (aliasOrIndex.charAt(0) == '+') { + // if its the first, add empty result set + if (i == 0) { + result = new HashSet(); + } add = true; aliasOrIndex = aliasOrIndex.substring(1); } else if (aliasOrIndex.charAt(0) == '-') { diff --git a/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java b/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java index 8533ad99393..74dc10b095a 100644 --- a/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java +++ b/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import static com.google.common.collect.Sets.newHashSet; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** @@ -61,46 +60,48 @@ public class MetaDataTests extends ElasticsearchTestCase { assertThat(newHashSet(md.convertFromWildcards(new String[]{"testYY*", "alias*"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("alias1", "alias2", "alias3", "testYYY"))); assertThat(newHashSet(md.convertFromWildcards(new String[]{"-kuku"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); assertThat(newHashSet(md.convertFromWildcards(new String[]{"+test*", "-testYYY"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"+testX*", "+testYYY"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"+testYYY", "+testX*"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); } private IndexMetaData.Builder indexBuilder(String index) { return IndexMetaData.builder(index).settings(ImmutableSettings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); } - + @Test(expected = IndexMissingException.class) public void concreteIndicesIgnoreIndicesOneMissingIndex() { - MetaData.Builder mdBuilder = MetaData.builder() - .put(indexBuilder("testXXX")) - .put(indexBuilder("kuku")); - MetaData md = mdBuilder.build(); - md.concreteIndices(new String[]{"testZZZ"}, IgnoreIndices.MISSING, true); + MetaData.Builder mdBuilder = MetaData.builder() + .put(indexBuilder("testXXX")) + .put(indexBuilder("kuku")); + MetaData md = mdBuilder.build(); + md.concreteIndices(new String[]{"testZZZ"}, IgnoreIndices.MISSING, true); } - + @Test public void concreteIndicesIgnoreIndicesOneMissingIndexOtherFound() { - MetaData.Builder mdBuilder = MetaData.builder() - .put(indexBuilder("testXXX")) - .put(indexBuilder("kuku")); - MetaData md = mdBuilder.build(); - assertThat(newHashSet(md.concreteIndices(new String[]{"testXXX","testZZZ"}, IgnoreIndices.MISSING, true)), equalTo(newHashSet("testXXX"))); + MetaData.Builder mdBuilder = MetaData.builder() + .put(indexBuilder("testXXX")) + .put(indexBuilder("kuku")); + MetaData md = mdBuilder.build(); + assertThat(newHashSet(md.concreteIndices(new String[]{"testXXX", "testZZZ"}, IgnoreIndices.MISSING, true)), equalTo(newHashSet("testXXX"))); } @Test(expected = IndexMissingException.class) public void concreteIndicesIgnoreIndicesAllMissing() { - MetaData.Builder mdBuilder = MetaData.builder() - .put(indexBuilder("testXXX")) - .put(indexBuilder("kuku")); - MetaData md = mdBuilder.build(); - assertThat(newHashSet(md.concreteIndices(new String[]{"testMo","testMahdy"}, IgnoreIndices.MISSING, true)), equalTo(newHashSet("testXXX"))); + MetaData.Builder mdBuilder = MetaData.builder() + .put(indexBuilder("testXXX")) + .put(indexBuilder("kuku")); + MetaData md = mdBuilder.build(); + assertThat(newHashSet(md.concreteIndices(new String[]{"testMo", "testMahdy"}, IgnoreIndices.MISSING, true)), equalTo(newHashSet("testXXX"))); } - + @Test public void concreteIndicesIgnoreIndicesEmptyRequest() { - MetaData.Builder mdBuilder = MetaData.builder() - .put(indexBuilder("testXXX")) - .put(indexBuilder("kuku")); - MetaData md = mdBuilder.build(); - assertThat(newHashSet(md.concreteIndices(new String[]{}, IgnoreIndices.MISSING, true)), equalTo(Sets.newHashSet("kuku","testXXX"))); + MetaData.Builder mdBuilder = MetaData.builder() + .put(indexBuilder("testXXX")) + .put(indexBuilder("kuku")); + MetaData md = mdBuilder.build(); + assertThat(newHashSet(md.concreteIndices(new String[]{}, IgnoreIndices.MISSING, true)), equalTo(Sets.newHashSet("kuku", "testXXX"))); } @Test