From d5b6de32959950c46b966eaac16de9cfbd0f392e Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 26 Mar 2014 11:31:53 +0100 Subject: [PATCH] Removed support for aliases as part of index settings Now that we have explicit support for aliases when creating indices and as part of index templates, we may remove support for aliases (only names) as part of index settings. This is partially breaking as the following calls: curl -XPUT localhost:9200/index -d '{ "settings" : { "aliases" : [ "alias1"] } } and curl -XPUT localhost:9200/index -d '{ "settings" : { "index.aliases" : [ "alias1"] } } were previously supported and will need to be replaced with curl -XPUT localhost:9200/index -d '{ "aliases" : { "alias1": {} } } Closes #5545 --- .../cluster/metadata/IndexMetaData.java | 13 ------------- .../metadata/ToAndFromJsonMetaDataTests.java | 15 ++++----------- .../AliasedIndexDocumentActionsTests.java | 5 +++-- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index b1c9f83eecf..db0ddc32faa 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -541,19 +541,6 @@ public class IndexMetaData { ImmutableOpenMap.Builder tmpAliases = aliases; Settings tmpSettings = settings; - // For backward compatibility - String[] legacyAliases = settings.getAsArray("index.aliases"); - if (legacyAliases.length > 0) { - tmpAliases = ImmutableOpenMap.builder(); - for (String alias : legacyAliases) { - AliasMetaData aliasMd = AliasMetaData.newAliasMetaDataBuilder(alias).build(); - tmpAliases.put(alias, aliasMd); - } - tmpAliases.putAll(aliases); - // Remove index.aliases from settings once they are migrated to the new data structure - tmpSettings = ImmutableSettings.settingsBuilder().put(settings).putArray("index.aliases").build(); - } - // update default mapping on the MappingMetaData if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) { MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING); diff --git a/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java b/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java index 65260f73557..07fab6f8591 100644 --- a/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java +++ b/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java @@ -68,9 +68,7 @@ public class ToAndFromJsonMetaDataTests extends ElasticsearchTestCase { .put(IndexMetaData.builder("test6") .settings(settingsBuilder() .put("setting1", "value1") - .put("setting2", "value2") - .put("index.aliases.0", "alias3") - .put("index.aliases.1", "alias1")) + .put("setting2", "value2")) .numberOfShards(1) .numberOfReplicas(2) .putMapping("mapping1", MAPPING_SOURCE1) @@ -80,9 +78,7 @@ public class ToAndFromJsonMetaDataTests extends ElasticsearchTestCase { .put(IndexMetaData.builder("test7") .settings(settingsBuilder() .put("setting1", "value1") - .put("setting2", "value2") - .put("index.aliases.0", "alias3") - .put("index.aliases.1", "alias1")) + .put("setting2", "value2")) .numberOfShards(1) .numberOfReplicas(2) .putMapping("mapping1", MAPPING_SOURCE1) @@ -159,10 +155,9 @@ public class ToAndFromJsonMetaDataTests extends ElasticsearchTestCase { assertThat(indexMetaData.mappings().size(), equalTo(2)); assertThat(indexMetaData.mappings().get("mapping1").source().string(), equalTo(MAPPING_SOURCE1)); assertThat(indexMetaData.mappings().get("mapping2").source().string(), equalTo(MAPPING_SOURCE2)); - assertThat(indexMetaData.aliases().size(), equalTo(3)); + assertThat(indexMetaData.aliases().size(), equalTo(2)); assertThat(indexMetaData.aliases().get("alias1").alias(), equalTo("alias1")); assertThat(indexMetaData.aliases().get("alias2").alias(), equalTo("alias2")); - assertThat(indexMetaData.aliases().get("alias3").alias(), equalTo("alias3")); indexMetaData = parsedMetaData.index("test7"); assertThat(indexMetaData.numberOfShards(), equalTo(1)); @@ -173,13 +168,11 @@ public class ToAndFromJsonMetaDataTests extends ElasticsearchTestCase { assertThat(indexMetaData.mappings().size(), equalTo(2)); assertThat(indexMetaData.mappings().get("mapping1").source().string(), equalTo(MAPPING_SOURCE1)); assertThat(indexMetaData.mappings().get("mapping2").source().string(), equalTo(MAPPING_SOURCE2)); - assertThat(indexMetaData.aliases().size(), equalTo(4)); + assertThat(indexMetaData.aliases().size(), equalTo(3)); assertThat(indexMetaData.aliases().get("alias1").alias(), equalTo("alias1")); assertThat(indexMetaData.aliases().get("alias1").filter().string(), equalTo(ALIAS_FILTER1)); assertThat(indexMetaData.aliases().get("alias2").alias(), equalTo("alias2")); assertThat(indexMetaData.aliases().get("alias2").filter(), nullValue()); - assertThat(indexMetaData.aliases().get("alias3").alias(), equalTo("alias3")); - assertThat(indexMetaData.aliases().get("alias3").filter(), nullValue()); assertThat(indexMetaData.aliases().get("alias4").alias(), equalTo("alias4")); assertThat(indexMetaData.aliases().get("alias4").filter().string(), equalTo(ALIAS_FILTER2)); diff --git a/src/test/java/org/elasticsearch/document/AliasedIndexDocumentActionsTests.java b/src/test/java/org/elasticsearch/document/AliasedIndexDocumentActionsTests.java index 727649e3832..3182799c253 100644 --- a/src/test/java/org/elasticsearch/document/AliasedIndexDocumentActionsTests.java +++ b/src/test/java/org/elasticsearch/document/AliasedIndexDocumentActionsTests.java @@ -19,8 +19,9 @@ package org.elasticsearch.document; +import org.elasticsearch.action.admin.indices.alias.Alias; + import static org.elasticsearch.client.Requests.createIndexRequest; -import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; /** * @@ -35,7 +36,7 @@ public class AliasedIndexDocumentActionsTests extends DocumentActionsTests { // ignore } logger.info("--> creating index test"); - client().admin().indices().create(createIndexRequest("test1").settings(settingsBuilder().putArray("index.aliases", "test"))).actionGet(); + client().admin().indices().create(createIndexRequest("test1").alias(new Alias("test"))).actionGet(); } @Override