Search in sources :

Example 6 with IndicesAliasesRequest

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

the class IndicesAdapterES7 method markIndexReopened.

@Override
public void markIndexReopened(String index) {
    final String aliasName = index + Indices.REOPENED_ALIAS_SUFFIX;
    final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    final IndicesAliasesRequest.AliasActions aliasAction = new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD).index(index).alias(aliasName);
    indicesAliasesRequest.addAliasAction(aliasAction);
    client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "Couldn't create reopened alias for index " + index);
}
Also used : IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)

Example 7 with IndicesAliasesRequest

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

the class RestIndexDeleteAliasesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
    IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
    indicesAliasesRequest.addAliasAction(AliasActions.remove().indices(indices).aliases(aliases));
    indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
    return channel -> client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) Settings(org.elasticsearch.common.settings.Settings) DELETE(org.elasticsearch.rest.RestRequest.Method.DELETE) RestRequest(org.elasticsearch.rest.RestRequest) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)

Example 8 with IndicesAliasesRequest

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

the class RestIndexPutAliasAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    String alias = request.param("name");
    Map<String, Object> filter = null;
    String routing = null;
    String indexRouting = null;
    String searchRouting = null;
    if (request.hasContent()) {
        try (XContentParser parser = request.contentParser()) {
            XContentParser.Token token = parser.nextToken();
            if (token == null) {
                throw new IllegalArgumentException("No index alias is specified");
            }
            String currentFieldName = null;
            while ((token = parser.nextToken()) != null) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token.isValue()) {
                    if ("index".equals(currentFieldName)) {
                        indices = Strings.splitStringByCommaToArray(parser.text());
                    } else if ("alias".equals(currentFieldName)) {
                        alias = parser.text();
                    } else if ("routing".equals(currentFieldName)) {
                        routing = parser.textOrNull();
                    } else if ("indexRouting".equals(currentFieldName) || "index-routing".equals(currentFieldName) || "index_routing".equals(currentFieldName)) {
                        indexRouting = parser.textOrNull();
                    } else if ("searchRouting".equals(currentFieldName) || "search-routing".equals(currentFieldName) || "search_routing".equals(currentFieldName)) {
                        searchRouting = parser.textOrNull();
                    }
                } else if (token == XContentParser.Token.START_OBJECT) {
                    if ("filter".equals(currentFieldName)) {
                        filter = parser.mapOrdered();
                    }
                }
            }
        }
    }
    IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
    indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
    IndicesAliasesRequest.AliasActions aliasAction = AliasActions.add().indices(indices).alias(alias);
    if (routing != null) {
        aliasAction.routing(routing);
    }
    if (searchRouting != null) {
        aliasAction.searchRouting(searchRouting);
    }
    if (indexRouting != null) {
        aliasAction.indexRouting(indexRouting);
    }
    if (filter != null) {
        aliasAction.filter(filter);
    }
    indicesAliasesRequest.addAliasAction(aliasAction);
    return channel -> client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) PUT(org.elasticsearch.rest.RestRequest.Method.PUT) Strings(org.elasticsearch.common.Strings) XContentParser(org.elasticsearch.common.xcontent.XContentParser) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 9 with IndicesAliasesRequest

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

the class IndicesTest method testAliasExists.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testAliasExists() throws Exception {
    assertThat(indices.aliasExists("graylog_alias")).isFalse();
    final IndicesAdminClient adminClient = client.admin().indices();
    final IndicesAliasesRequest request = adminClient.prepareAliases().addAlias(INDEX_NAME, "graylog_alias").request();
    final IndicesAliasesResponse response = adminClient.aliases(request).actionGet(ES_TIMEOUT);
    assertThat(response.isAcknowledged()).isTrue();
    assertThat(indices.aliasExists("graylog_alias")).isTrue();
}
Also used : IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 10 with IndicesAliasesRequest

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

the class IndicesAdapterES7 method cycleAlias.

@Override
public void cycleAlias(String aliasName, String targetIndex, String oldIndex) {
    final IndicesAliasesRequest.AliasActions addAlias = new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD).index(targetIndex).alias(aliasName);
    final IndicesAliasesRequest.AliasActions removeAlias = new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.REMOVE).index(oldIndex).alias(aliasName);
    final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest().addAliasAction(removeAlias).addAliasAction(addAlias);
    client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "Couldn't switch alias " + aliasName + " from index " + oldIndex + " to index " + targetIndex);
}
Also used : IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)

Aggregations

IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)8 IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)5 IOException (java.io.IOException)3 AliasActions (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)3 NodeClient (org.elasticsearch.client.node.NodeClient)3 Settings (org.elasticsearch.common.settings.Settings)3 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)3 RestController (org.elasticsearch.rest.RestController)3 RestRequest (org.elasticsearch.rest.RestRequest)3 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)3 Test (org.junit.Test)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)2 Strings (org.elasticsearch.common.Strings)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ClusterSearchShardsRequest (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)1