Skip to content

Commit

Permalink
Make XContentBuilder in AliasActions build is_write_index field (#3…
Browse files Browse the repository at this point in the history
…5071)

Make XContentBuilder in AliasesActions build `is_write_index` field
  • Loading branch information
upgle authored and talevy committed Oct 31, 2018
1 parent 38294b7 commit 4de8c43
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,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);
IndicesAliasesResponse aliasesAddResponse = execute(aliasesAddRequest, highLevelClient().indices()::updateAliases,
Expand All @@ -553,6 +556,8 @@ public void testUpdateAliases() throws IOException {
Map<String, Object> filter = (Map<String, Object>) getAlias.get("filter");
Map<String, Object> term = (Map<String, Object>) 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -491,6 +494,7 @@ public String toString() {
+ ",routing=" + routing
+ ",indexRouting=" + indexRouting
+ ",searchRouting=" + searchRouting
+ ",writeIndex=" + writeIndex
+ "]";
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public static AliasActions randomAliasAction(boolean useStringAsFilter) {
action.indexRouting(randomRouting().toString());
}
}
if (randomBoolean()) {
action.writeIndex(randomBoolean());
}
}
return action;
}
Expand Down

0 comments on commit 4de8c43

Please sign in to comment.