Skip to content
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

Fix create or update alias API doesn't throw exception for unsupported parameters #14719

Merged
merged 3 commits into from
Jul 15, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix FuzzyQuery in keyword field will use IndexOrDocValuesQuery when both of index and doc_value are true ([#14378](https://github.com/opensearch-project/OpenSearch/pull/14378))
- Fix file cache initialization ([#14004](https://github.com/opensearch-project/OpenSearch/pull/14004))
- Handle NPE in GetResult if "found" field is missing ([#14552](https://github.com/opensearch-project/OpenSearch/pull/14552))
- Fix create or update alias API doesn't throw exception for unsupported parameters ([#14719](https://github.com/opensearch-project/OpenSearch/pull/14719))
- Refactoring FilterPath.parse by using an iterative approach ([#14200](https://github.com/opensearch-project/OpenSearch/pull/14200))
- Refactoring Grok.validatePatternBank by using an iterative approach ([#14206](https://github.com/opensearch-project/OpenSearch/pull/14206))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,62 @@
"description":"The name of the alias to be created or updated"
}
}
},
{
"path":"/{index}/_alias",
"methods":[
"PUT"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the alias should point to (supports wildcards); use `_all` to perform the operation on all indices."
}
}
},
{
"path":"/{index}/_aliases",
"methods":[
"PUT"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the alias should point to (supports wildcards); use `_all` to perform the operation on all indices."
}
}
},
{
"path":"/_alias/{name}",
"methods":[
"PUT",
"POST"
],
"parts":{
"name":{
"type":"string",
"description":"The name of the alias to be created or updated"
}
}
},
{
"path":"/_aliases/{name}",
"methods":[
"PUT",
"POST"
],
"parts":{
"name":{
"type":"string",
"description":"The name of the alias to be created or updated"
}
}
},
{
"path":"/_alias",
"methods":[
"PUT"
]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@

- match: {test_index.aliases.test_alias: {}}

- do:
indices.put_alias:
index: test_index
body: {"alias": "test_alias_1"}

- do:
indices.get_alias:
index: test_index
name: test_alias_1

- match: {test_index.aliases.test_alias_1: {}}

- do:
indices.put_alias:
name: test_alias_2
body: {"index": "test_index"}

- do:
indices.get_alias:
index: test_index
name: test_alias_2

- match: {test_index.aliases.test_alias_2: {}}

- do:
catch: bad_request
indices.put_alias:
index: null
name: null

---
"Can't create alias with invalid characters":

Expand Down Expand Up @@ -102,3 +132,179 @@
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: {"filter": {"range": {"date_nanos_field": {"gt": "now-7d/d"}}}}}

---
"Can set index_routing":
- do:
indices.create:
index: test_index

- do:
indices.put_alias:
index: test_index
name: test_alias
body:
index_routing: "test"

- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { 'index_routing': "test" }}

---
"Can set routing":
- do:
indices.create:
index: test_index

- do:
indices.put_alias:
index: test_index
name: test_alias
body:
routing: "test"

- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { 'index_routing': "test", 'search_routing': "test" }}

---
"Can set search_routing":
- do:
indices.create:
index: test_index

- do:
indices.put_alias:
index: test_index
name: test_alias
body:
search_routing: "test"

- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { 'search_routing': "test" }}

---
"Index parameter supports multiple values":
- do:
indices.create:
index: test_index
- do:
indices.create:
index: test_index1

- do:
indices.put_alias:
index: test_index,test_index1
name: test_alias

- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { }}
- do:
indices.get_alias:
index: test_index1
name: test_alias
- match: {test_index1.aliases.test_alias: { }}

- do:
indices.put_alias:
body: {"index": "test_index,test_index1", "alias": "test_alias_1"}

- do:
indices.get_alias:
index: test_index
name: test_alias_1
- match: {test_index.aliases.test_alias_1: { }}
- do:
indices.get_alias:
index: test_index1
name: test_alias_1
- match: {test_index1.aliases.test_alias_1: { }}

---
"Index and alias in request body can override path parameters":
- do:
indices.create:
index: test_index

- do:
indices.put_alias:
index: test_index_unknown
name: test_alias
body: {"index": "test_index"}

- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { }}

- do:
indices.put_alias:
index: test_index
name: test_alias_unknown
body: {"alias": "test_alias_2"}

- do:
indices.get_alias:
index: test_index
name: test_alias_2
- match: {test_index.aliases.test_alias_2: { }}

- do:
indices.put_alias:
body: {"index": "test_index", "alias": "test_alias_3"}

- do:
indices.get_alias:
index: test_index
name: test_alias_3
- match: {test_index.aliases.test_alias_3: { }}

---
"Can set is_hidden":
- skip:
version: " - 2.99.99"
reason: "Fix was introduced in 3.0.0"
- do:
indices.create:
index: test_index

- do:
indices.put_alias:
index: test_index
name: test_alias
body:
is_hidden: true

- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { 'is_hidden': true }}

---
"Throws exception with invalid parameters":
- skip:
version: " - 2.99.99"
reason: "Fix was introduced in 3.0.0"

- do:
indices.create:
index: test_index

- do:
catch: /unknown field \[abc\]/
indices.put_alias:
index: test_index
name: test_alias
body: {"abc": 1}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
String indexRouting = null;
String searchRouting = null;
Boolean writeIndex = null;
Boolean isHidden = null;

if (request.hasContent()) {
try (XContentParser parser = request.contentParser()) {
Expand Down Expand Up @@ -120,10 +121,16 @@
searchRouting = parser.textOrNull();
} else if ("is_write_index".equals(currentFieldName)) {
writeIndex = parser.booleanValue();
} else if ("is_hidden".equals(currentFieldName)) {
reta marked this conversation as resolved.
Show resolved Hide resolved
isHidden = parser.booleanValue();

Check warning on line 125 in server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java#L125

Added line #L125 was not covered by tests
} else {
throw new IllegalArgumentException("unknown field [" + currentFieldName + "]");

Check warning on line 127 in server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java#L127

Added line #L127 was not covered by tests
}
} else if (token == XContentParser.Token.START_OBJECT) {
if ("filter".equals(currentFieldName)) {
filter = parser.mapOrdered();
} else {
throw new IllegalArgumentException("unknown field [" + currentFieldName + "]");

Check warning on line 133 in server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java#L133

Added line #L133 was not covered by tests
}
}
}
Expand Down Expand Up @@ -153,6 +160,9 @@
if (writeIndex != null) {
aliasAction.writeIndex(writeIndex);
}
if (isHidden != null) {
aliasAction.isHidden(isHidden);

Check warning on line 164 in server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/admin/indices/RestIndexPutAliasAction.java#L164

Added line #L164 was not covered by tests
}
indicesAliasesRequest.addAliasAction(aliasAction);
return channel -> client.admin().indices().aliases(indicesAliasesRequest, new RestToXContentListener<>(channel));
}
Expand Down
Loading