Skip to content

Commit 68a8d13

Browse files
authored
add support for is_write_index in put-alias body parsing (#31674)
* add support for is_write_index in put-alias body parsing The Rest Put-Alias Action does separate parsing of the alias body to construct the IndicesAliasesRequest. This extra parsing was missed in #30703. * test flag was not just ignored by the parser * disable backcompat tests
1 parent 3428dc2 commit 68a8d13

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ task verifyVersions {
173173
* the enabled state of every bwc task. It should be set back to true
174174
* after the backport of the backcompat code is complete.
175175
*/
176-
final boolean bwc_tests_enabled = true
177-
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
176+
final boolean bwc_tests_enabled = false
177+
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/31674" /* place a PR link here when committing bwc changes */
178178
if (bwc_tests_enabled == false) {
179179
if (bwc_tests_disabled_issue.isEmpty()) {
180180
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")

rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_alias/10_basic.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,27 @@
5656
indices.put_alias:
5757
index: test_index
5858
name: foo
59+
60+
---
61+
"Can set is_write_index":
62+
63+
- skip:
64+
version: " - 6.3.99"
65+
reason: "is_write_index is only available from 6.4.0 on"
66+
67+
- do:
68+
indices.create:
69+
index: test_index
70+
71+
- do:
72+
indices.put_alias:
73+
index: test_index
74+
name: test_alias
75+
body:
76+
is_write_index: true
77+
78+
- do:
79+
indices.get_alias:
80+
index: test_index
81+
name: test_alias
82+
- match: {test_index.aliases.test_alias: { 'is_write_index': true }}

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
6666
String routing = null;
6767
String indexRouting = null;
6868
String searchRouting = null;
69+
Boolean writeIndex = null;
6970

7071
if (request.hasContent()) {
7172
try (XContentParser parser = request.contentParser()) {
@@ -90,6 +91,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
9091
} else if ("searchRouting".equals(currentFieldName)
9192
|| "search-routing".equals(currentFieldName) || "search_routing".equals(currentFieldName)) {
9293
searchRouting = parser.textOrNull();
94+
} else if ("is_write_index".equals(currentFieldName)) {
95+
writeIndex = parser.booleanValue();
9396
}
9497
} else if (token == XContentParser.Token.START_OBJECT) {
9598
if ("filter".equals(currentFieldName)) {
@@ -117,6 +120,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
117120
if (filter != null) {
118121
aliasAction.filter(filter);
119122
}
123+
if (writeIndex != null) {
124+
aliasAction.writeIndex(writeIndex);
125+
}
120126
indicesAliasesRequest.addAliasAction(aliasAction);
121127
return channel -> client.admin().indices().aliases(indicesAliasesRequest, new RestToXContentListener<>(channel));
122128
}

0 commit comments

Comments
 (0)