Skip to content

Throw exception for unsupported values type in Alias #124737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/124737.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 124737
summary: Throw exception for unsupported values type in Alias
area: Indices APIs
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,38 @@
- is_false: test_index.aliases.test_clias.index_routing
- is_false: test_index.aliases.test_clias.search_routing

---
"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\]/
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":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,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 + "]");
Expand Down
10 changes: 9 additions & 1 deletion server/src/main/java/org/elasticsearch/index/IndexFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ public Set<NodeFeature> 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<NodeFeature> 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
);
}
}
Loading