diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 9726e8a3239..cd74e48b641 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -50,7 +50,7 @@ import java.util.regex.Pattern; import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.common.collect.MapBuilder.*; -import static org.elasticsearch.common.collect.Maps.newHashMap; +import static org.elasticsearch.common.collect.Maps.*; import static org.elasticsearch.common.collect.Sets.*; import static org.elasticsearch.common.settings.ImmutableSettings.*; @@ -231,7 +231,7 @@ public class MetaData implements Iterable { return routing; } if (indexAliases.size() > 1) { - throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has more than one indices associated with it [" + indexAliases.keySet() + "], can't execute a single index op"); + throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has more than one index associated with it [" + indexAliases.keySet() + "], can't execute a single index op"); } AliasMetaData aliasMd = indexAliases.values().iterator().next(); if (aliasMd.indexRouting() != null) { @@ -239,7 +239,7 @@ public class MetaData implements Iterable { if (routing.equals(aliasMd.indexRouting())) { return routing; } else { - return null; + throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has index routing associated with it [" + aliasMd.indexRouting() + "], and was provided with routing value [" + routing + "], rejecting operation"); } } return aliasMd.indexRouting(); diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java index 87287b856f2..9561e058b20 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java @@ -30,12 +30,11 @@ import org.testng.annotations.Test; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; -import static org.elasticsearch.cluster.metadata.AliasAction.newAddAliasAction; -import static org.elasticsearch.common.collect.Maps.newHashMap; -import static org.elasticsearch.common.collect.Sets.newHashSet; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.elasticsearch.cluster.metadata.AliasAction.*; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.collect.Sets.*; +import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; /** @@ -92,7 +91,11 @@ public class AliasResolveRoutingTests extends AbstractNodesTests { assertThat(clusterService.state().metaData().resolveIndexRouting(null, "alias21"), equalTo("1")); assertThat(clusterService.state().metaData().resolveIndexRouting("3", "test1"), equalTo("3")); assertThat(clusterService.state().metaData().resolveIndexRouting("0", "alias10"), equalTo("0")); - assertThat(clusterService.state().metaData().resolveIndexRouting("1", "alias10"), nullValue()); + try { + clusterService.state().metaData().resolveIndexRouting("1", "alias10"); + } catch (ElasticSearchIllegalArgumentException e) { + // all is well, we can't have two mappings, one provided, and one in the alias + } try { clusterService.state().metaData().resolveIndexRouting(null, "alias0");