File tree Expand file tree Collapse file tree 4 files changed +66
-1
lines changed
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create
server/src/main/java/org/elasticsearch
action/admin/indices/alias Expand file tree Collapse file tree 4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 1+ pr : 124737
2+ summary : Throw exception for unsupported values type in Alias
3+ area : Indices APIs
4+ type : enhancement
5+ issues : []
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 + "]" );
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments