diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 832aba51e2b41..053f46f8496b0 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -522,6 +522,9 @@ public void testUpdateAliases() throws IOException { IndicesAliasesRequest aliasesAddRequest = new IndicesAliasesRequest(); AliasActions addAction = new AliasActions(AliasActions.Type.ADD).index(index).aliases(alias); + if (randomBoolean()) { + addAction.writeIndex(randomBoolean()); + } addAction.routing("routing").searchRouting("search_routing").filter("{\"term\":{\"year\":2016}}"); aliasesAddRequest.addAliasAction(addAction); AcknowledgedResponse aliasesAddResponse = execute(aliasesAddRequest, highLevelClient().indices()::updateAliases, @@ -535,6 +538,8 @@ public void testUpdateAliases() throws IOException { Map filter = (Map) getAlias.get("filter"); Map term = (Map) filter.get("term"); assertEquals(2016, term.get("year")); + Boolean isWriteIndex = (Boolean) getAlias.get("is_write_index"); + assertThat(isWriteIndex, equalTo(addAction.writeIndex())); String alias2 = "alias2"; IndicesAliasesRequest aliasesAddRemoveRequest = new IndicesAliasesRequest(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java index 22e8554ed6aa6..dfe0a25c6110a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java @@ -486,6 +486,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (false == Strings.isEmpty(searchRouting)) { builder.field(SEARCH_ROUTING.getPreferredName(), searchRouting); } + if (null != writeIndex) { + builder.field(IS_WRITE_INDEX.getPreferredName(), writeIndex); + } builder.endObject(); builder.endObject(); return builder; @@ -505,6 +508,7 @@ public String toString() { + ",routing=" + routing + ",indexRouting=" + indexRouting + ",searchRouting=" + searchRouting + + ",writeIndex=" + writeIndex + "]"; } @@ -521,12 +525,13 @@ public boolean equals(Object obj) { && Objects.equals(filter, other.filter) && Objects.equals(routing, other.routing) && Objects.equals(indexRouting, other.indexRouting) - && Objects.equals(searchRouting, other.searchRouting); + && Objects.equals(searchRouting, other.searchRouting) + && Objects.equals(writeIndex, other.writeIndex); } @Override public int hashCode() { - return Objects.hash(type, indices, aliases, filter, routing, indexRouting, searchRouting); + return Objects.hash(type, indices, aliases, filter, routing, indexRouting, searchRouting, writeIndex); } } diff --git a/test/framework/src/main/java/org/elasticsearch/index/alias/RandomAliasActionsGenerator.java b/test/framework/src/main/java/org/elasticsearch/index/alias/RandomAliasActionsGenerator.java index d4d2d78789b8e..e8a554ca4aaae 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/alias/RandomAliasActionsGenerator.java +++ b/test/framework/src/main/java/org/elasticsearch/index/alias/RandomAliasActionsGenerator.java @@ -82,6 +82,9 @@ public static AliasActions randomAliasAction(boolean useStringAsFilter) { action.indexRouting(randomRouting().toString()); } } + if (randomBoolean()) { + action.writeIndex(randomBoolean()); + } } return action; }