diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java index be2968de06c..63c293e13c9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.indices.InvalidAliasNameException; import java.util.Set; @@ -57,6 +58,10 @@ public class MetaDataIndexAliasesService extends AbstractComponent { listener.onFailure(new IndexMissingException(new Index(aliasAction.index()))); return currentState; } + if (currentState.metaData().hasIndex(aliasAction.alias())) { + listener.onFailure(new InvalidAliasNameException(new Index(aliasAction.index()), aliasAction.alias(), "an index exists with the same name as the alias")); + return currentState; + } } MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 8aa4384b93d..501bf0590b9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -31,12 +31,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.Index; import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.InvalidTypeNameException; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.index.service.IndexService; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.indices.InvalidTypeNameException; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java index f03ca73204c..aaf0b41fa1c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -40,6 +40,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser; import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.indices.InvalidTypeNameException; import javax.annotation.Nullable; import java.io.File; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java new file mode 100644 index 00000000000..8c91aaff98c --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java @@ -0,0 +1,33 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.indices; + +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexException; + +/** + * @author kimchy (shay.banon) + */ +public class InvalidAliasNameException extends IndexException { + + public InvalidAliasNameException(Index index, String name, String desc) { + super(index, "Invalid alias name [" + name + "], " + desc); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/InvalidTypeNameException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java similarity index 91% rename from modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/InvalidTypeNameException.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java index 3c8698e9c5b..b7db76ca34e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/InvalidTypeNameException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java @@ -17,7 +17,9 @@ * under the License. */ -package org.elasticsearch.index.mapper; +package org.elasticsearch.indices; + +import org.elasticsearch.index.mapper.MapperException; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java index 432760b093f..85f7d8d3575 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java @@ -26,9 +26,9 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.mapper.InvalidTypeNameException; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.indices.InvalidTypeNameException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java index 79db01d7bca..0b902784b38 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java @@ -26,9 +26,9 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.mapper.InvalidTypeNameException; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.indices.InvalidTypeNameException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder;