Skip to content

Commit 5ca5723

Browse files
authored
Merge branch 'main' into feature/dangling-spaces
2 parents 194cf15 + 637807c commit 5ca5723

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

docs/changelog/124737.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124737
2+
summary: Throw exception for unsupported values type in Alias
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,38 @@
8686
- is_false: test_index.aliases.test_clias.index_routing
8787
- is_false: test_index.aliases.test_clias.search_routing
8888

89+
---
90+
"Throw exception for unsupported value type":
91+
- requires:
92+
cluster_features: [ "index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias" ]
93+
reason: "Throw exception on index creation if unsupported value type in alias"
94+
95+
- do:
96+
catch: /Unsupported String type value \[true\] for field \[is_write_index\] in alias \[test_alias\]/
97+
indices.create:
98+
index: test_index
99+
body:
100+
mappings:
101+
properties:
102+
field:
103+
type: text
104+
aliases:
105+
test_alias:
106+
is_write_index: "true"
107+
108+
- do:
109+
catch: /Unsupported boolean type value \[true\] for field \[routing\] in alias \[test_alias\]/
110+
indices.create:
111+
index: test_index
112+
body:
113+
mappings:
114+
properties:
115+
field:
116+
type: text
117+
aliases:
118+
test_alias:
119+
routing: true
120+
89121
---
90122
"Create index with write aliases":
91123

server/src/main/java/org/elasticsearch/action/admin/indices/alias/Alias.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,32 @@ public static Alias fromXContent(XContentParser parser) throws IOException {
257257
alias.indexRouting(parser.text());
258258
} else if (SEARCH_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
259259
alias.searchRouting(parser.text());
260+
} else {
261+
throw new IllegalArgumentException(
262+
"Unsupported String type value ["
263+
+ parser.text()
264+
+ "] for field ["
265+
+ currentFieldName
266+
+ "] in alias ["
267+
+ alias.name
268+
+ "]"
269+
);
260270
}
261271
} else if (token == XContentParser.Token.VALUE_BOOLEAN) {
262272
if (IS_WRITE_INDEX.match(currentFieldName, parser.getDeprecationHandler())) {
263273
alias.writeIndex(parser.booleanValue());
264274
} else if (IS_HIDDEN.match(currentFieldName, parser.getDeprecationHandler())) {
265275
alias.isHidden(parser.booleanValue());
276+
} else {
277+
throw new IllegalArgumentException(
278+
"Unsupported boolean type value ["
279+
+ parser.text()
280+
+ "] for field ["
281+
+ currentFieldName
282+
+ "] in alias ["
283+
+ alias.name
284+
+ "]"
285+
);
266286
}
267287
} else {
268288
throw new IllegalArgumentException("Unknown token [" + token + "] in alias [" + alias.name + "]");

server/src/main/java/org/elasticsearch/index/IndexFeatures.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ public Set<NodeFeature> getFeatures() {
2525

2626
private static final NodeFeature SYNONYMS_SET_LENIENT_ON_NON_EXISTING = new NodeFeature("index.synonyms_set_lenient_on_non_existing");
2727

28+
private static final NodeFeature THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS = new NodeFeature(
29+
"index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias"
30+
);
31+
2832
@Override
2933
public Set<NodeFeature> getTestFeatures() {
30-
return Set.of(LOGSDB_NO_HOST_NAME_FIELD, SYNONYMS_SET_LENIENT_ON_NON_EXISTING);
34+
return Set.of(
35+
LOGSDB_NO_HOST_NAME_FIELD,
36+
SYNONYMS_SET_LENIENT_ON_NON_EXISTING,
37+
THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS
38+
);
3139
}
3240
}

0 commit comments

Comments
 (0)