Search in sources :

Example 11 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.

the class AliasActionsTests method testParseRemove.

public void testParseRemove() throws IOException {
    String[] indices = generateRandomStringArray(10, 5, false, false);
    String[] aliases = generateRandomStringArray(10, 5, false, false);
    XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
    b.startObject();
    {
        b.startObject("remove");
        {
            if (indices.length > 1 || randomBoolean()) {
                b.array("indices", indices);
            } else {
                b.field("index", indices[0]);
            }
            if (aliases.length > 1 || randomBoolean()) {
                b.array("aliases", aliases);
            } else {
                b.field("alias", aliases[0]);
            }
        }
        b.endObject();
    }
    b.endObject();
    b = shuffleXContent(b);
    try (XContentParser parser = createParser(b)) {
        AliasActions action = AliasActions.PARSER.apply(parser, null);
        assertEquals(AliasActions.Type.REMOVE, action.actionType());
        assertThat(action.indices(), equalTo(indices));
        assertThat(action.aliases(), equalTo(aliases));
    }
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Example 12 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project graylog2-server by Graylog2.

the class ClientES7 method addAliasMapping.

@Override
public void addAliasMapping(String indexName, String alias) {
    final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    final AliasActions aliasAction = new AliasActions(AliasActions.Type.ADD).index(indexName).alias(alias);
    indicesAliasesRequest.addAliasAction(aliasAction);
    client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "failed to add alias " + alias + " for index " + indexName);
}
Also used : IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) AliasActions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Aggregations

AliasActions (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)10 IOException (java.io.IOException)4 ParsingException (org.elasticsearch.common.ParsingException)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 XContentParser (org.elasticsearch.common.xcontent.XContentParser)4 IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 AliasActions (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ClusterStateUpdateResponse (org.elasticsearch.cluster.ack.ClusterStateUpdateResponse)1 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)1 AliasAction (org.elasticsearch.cluster.metadata.AliasAction)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1 AliasesNotFoundException (org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException)1