From 173297fc99bfcfca6762639f7318686855fe3296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=BF=E5=AF=8C?= Date: Thu, 13 Mar 2025 20:09:18 +0800 Subject: [PATCH 1/4] Throw exception for unsupported values type in Alias --- .../action/admin/indices/alias/Alias.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/Alias.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/Alias.java index bb202dc6c3772..5957be084ccd7 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/Alias.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/Alias.java @@ -256,12 +256,32 @@ public static Alias fromXContent(XContentParser parser) throws IOException { alias.indexRouting(parser.text()); } else if (SEARCH_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) { alias.searchRouting(parser.text()); + } else { + throw new IllegalArgumentException( + "Unsupported String type value [" + + parser.text() + + "] for field [" + + currentFieldName + + "] in alias [" + + alias.name + + "]" + ); } } else if (token == XContentParser.Token.VALUE_BOOLEAN) { if (IS_WRITE_INDEX.match(currentFieldName, parser.getDeprecationHandler())) { alias.writeIndex(parser.booleanValue()); } else if (IS_HIDDEN.match(currentFieldName, parser.getDeprecationHandler())) { alias.isHidden(parser.booleanValue()); + } else { + throw new IllegalArgumentException( + "Unsupported boolean type value [" + + parser.text() + + "] for field [" + + currentFieldName + + "] in alias [" + + alias.name + + "]" + ); } } else { throw new IllegalArgumentException("Unknown token [" + token + "] in alias [" + alias.name + "]"); From 29a5de04492c2eedea6c829001afb5f31547f347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=BF=E5=AF=8C?= Date: Thu, 13 Mar 2025 20:43:05 +0800 Subject: [PATCH 2/4] add changelog --- docs/changelog/124737.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/124737.yaml diff --git a/docs/changelog/124737.yaml b/docs/changelog/124737.yaml new file mode 100644 index 0000000000000..d7a3b370d72d4 --- /dev/null +++ b/docs/changelog/124737.yaml @@ -0,0 +1,5 @@ +pr: 124737 +summary: Throw exception for unsupported values type in Alias +area: Indices APIs +type: enhancement +issues: [] From a3f9243f3adaaf4aaf85c3da748bcb2ab394cd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=BF=E5=AF=8C?= Date: Sat, 22 Mar 2025 11:59:44 +0800 Subject: [PATCH 3/4] add yamlRestTest --- .../test/indices.create/10_basic.yml | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml index f9ea2f63351ff..8f7244cefdc16 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml @@ -86,6 +86,35 @@ - is_false: test_index.aliases.test_clias.index_routing - is_false: test_index.aliases.test_clias.search_routing +--- + "Throw exception for unsupported value type": + + - do: + catch: /Unsupported String type value \[true\] for field \[is_write_index\] in alias \[test_alias\]/ + indices.create: + index: test_index + body: + mappings: + properties: + field: + type: text + aliases: + test_alias: + is_write_index: "true" + + - do: + catch: /Unsupported boolean type value \[true\] for field \[routing\] in alias \[test_alias\]/ + indices.create: + index: test_index + body: + mappings: + properties: + field: + type: text + aliases: + test_alias: + routing: true + --- "Create index with write aliases": From 6bf3063ad864d406d4e56169da27de8f2af136a9 Mon Sep 17 00:00:00 2001 From: mushaoqiong Date: Sun, 20 Apr 2025 20:32:29 +0800 Subject: [PATCH 4/4] add test feature for test --- .../rest-api-spec/test/indices.create/10_basic.yml | 3 +++ .../java/org/elasticsearch/index/IndexFeatures.java | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml index 8f7244cefdc16..533726436c548 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml @@ -88,6 +88,9 @@ --- "Throw exception for unsupported value type": + - requires: + cluster_features: [ "index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias" ] + reason: "Throw exception on index creation if unsupported value type in alias" - do: catch: /Unsupported String type value \[true\] for field \[is_write_index\] in alias \[test_alias\]/ diff --git a/server/src/main/java/org/elasticsearch/index/IndexFeatures.java b/server/src/main/java/org/elasticsearch/index/IndexFeatures.java index c1abf1f670756..912dadecb5a44 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexFeatures.java +++ b/server/src/main/java/org/elasticsearch/index/IndexFeatures.java @@ -25,8 +25,16 @@ public Set getFeatures() { private static final NodeFeature SYNONYMS_SET_LENIENT_ON_NON_EXISTING = new NodeFeature("index.synonyms_set_lenient_on_non_existing"); + private static final NodeFeature THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS = new NodeFeature( + "index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias" + ); + @Override public Set getTestFeatures() { - return Set.of(LOGSDB_NO_HOST_NAME_FIELD, SYNONYMS_SET_LENIENT_ON_NON_EXISTING); + return Set.of( + LOGSDB_NO_HOST_NAME_FIELD, + SYNONYMS_SET_LENIENT_ON_NON_EXISTING, + THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS + ); } }