Make XContentBuilder in AliasActions build `is_write_index` field (#35071)

Make XContentBuilder in AliasesActions build `is_write_index` field
This commit is contained in:
Seong-hyun, Oh 2018-11-01 06:15:46 +09:00 committed by Tal Levy
parent d181d1bab1
commit 9ef4788c13
3 changed files with 15 additions and 2 deletions

View File

@ -522,6 +522,9 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
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 class IndicesClientIT extends ESRestHighLevelClientTestCase {
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();

View File

@ -486,6 +486,9 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
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 class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
+ ",routing=" + routing
+ ",indexRouting=" + indexRouting
+ ",searchRouting=" + searchRouting
+ ",writeIndex=" + writeIndex
+ "]";
}
@ -521,12 +525,13 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
&& 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);
}
}

View File

@ -82,6 +82,9 @@ public final class RandomAliasActionsGenerator {
action.indexRouting(randomRouting().toString());
}
}
if (randomBoolean()) {
action.writeIndex(randomBoolean());
}
}
return action;
}