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 2c421597c68d0..927183ba7715f 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 @@ -534,6 +534,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, @@ -548,6 +551,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 9249550871c12..c1d921ff0324f 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 @@ -472,6 +472,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; @@ -491,6 +494,7 @@ public String toString() { + ",routing=" + routing + ",indexRouting=" + indexRouting + ",searchRouting=" + searchRouting + + ",writeIndex=" + writeIndex + "]"; } @@ -507,12 +511,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; }