Search in sources :

Example 1 with IndicesAliasesClusterStateUpdateRequest

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest in project elasticsearch by elastic.

the class TransportRolloverAction method prepareRolloverAliasesUpdateRequest.

static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesUpdateRequest(String oldIndex, String newIndex, RolloverRequest request) {
    List<AliasAction> actions = unmodifiableList(Arrays.asList(new AliasAction.Add(newIndex, request.getAlias(), null, null, null), new AliasAction.Remove(oldIndex, request.getAlias())));
    final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest(actions).ackTimeout(request.ackTimeout()).masterNodeTimeout(request.masterNodeTimeout());
    return updateRequest;
}
Also used : AliasAction(org.elasticsearch.cluster.metadata.AliasAction) IndicesAliasesClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest)

Example 2 with IndicesAliasesClusterStateUpdateRequest

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest in project elasticsearch by elastic.

the class TransportRolloverActionTests method testCreateUpdateAliasRequest.

public void testCreateUpdateAliasRequest() throws Exception {
    String sourceAlias = randomAsciiOfLength(10);
    String sourceIndex = randomAsciiOfLength(10);
    String targetIndex = randomAsciiOfLength(10);
    final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, targetIndex);
    final IndicesAliasesClusterStateUpdateRequest updateRequest = TransportRolloverAction.prepareRolloverAliasesUpdateRequest(sourceIndex, targetIndex, rolloverRequest);
    List<AliasAction> actions = updateRequest.actions();
    assertThat(actions, hasSize(2));
    boolean foundAdd = false;
    boolean foundRemove = false;
    for (AliasAction action : actions) {
        if (action.getIndex().equals(targetIndex)) {
            assertEquals(sourceAlias, ((AliasAction.Add) action).getAlias());
            foundAdd = true;
        } else if (action.getIndex().equals(sourceIndex)) {
            assertEquals(sourceAlias, ((AliasAction.Remove) action).getAlias());
            foundRemove = true;
        } else {
            throw new AssertionError("Unknow index [" + action.getIndex() + "]");
        }
    }
    assertTrue(foundAdd);
    assertTrue(foundRemove);
}
Also used : AliasAction(org.elasticsearch.cluster.metadata.AliasAction) IndicesAliasesClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest)

Aggregations

IndicesAliasesClusterStateUpdateRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest)2 AliasAction (org.elasticsearch.cluster.metadata.AliasAction)2