Package org.elasticsearch.action.admin.indices.alias

Examples of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest$AliasActions


     * Creates an index aliases request allowing to add and remove aliases.
     *
     * @return The index aliases request
     */
    public static IndicesAliasesRequest indexAliasesRequest() {
        return new IndicesAliasesRequest();
    }
View Full Code Here


* @author kimchy (shay.banon)
*/
public class IndicesAliasesRequestBuilder extends BaseIndicesRequestBuilder<IndicesAliasesRequest, IndicesAliasesResponse> {

    public IndicesAliasesRequestBuilder(IndicesAdminClient indicesClient) {
        super(indicesClient, new IndicesAliasesRequest());
    }
View Full Code Here

        super(settings, client);
        controller.registerHandler(POST, "/_aliases", this);
    }

    @Override public void handleRequest(final RestRequest request, final RestChannel channel) {
        IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
        try {
            // {
            //     actions : [
            //         { add : { index : "test1", alias : "alias1", filter : {"user" : "kimchy"} } }
            //         { remove : { index : "test1", alias : "alias1" } }
            //     ]
            // }
            indicesAliasesRequest.timeout(request.paramAsTime("timeout", timeValueSeconds(10)));
            XContentParser parser = XContentFactory.xContent(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength())
                    .createParser(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength());
            XContentParser.Token token = parser.nextToken();
            if (token == null) {
                throw new ElasticSearchIllegalArgumentException("No action is specified");
            }
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.START_ARRAY) {
                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                        if (token == XContentParser.Token.FIELD_NAME) {
                            String action = parser.currentName();
                            AliasAction.Type type;
                            if ("add".equals(action)) {
                                type = AliasAction.Type.ADD;
                            } else if ("remove".equals(action)) {
                                type = AliasAction.Type.REMOVE;
                            } else {
                                throw new ElasticSearchIllegalArgumentException("Alias action [" + action + "] not supported");
                            }
                            String index = null;
                            String alias = null;
                            Map<String, Object> filter = null;
                            String routing = null;
                            boolean routingSet = false;
                            String indexRouting = null;
                            boolean indexRoutingSet = false;
                            String searchRouting = null;
                            boolean searchRoutingSet = false;
                            String currentFieldName = null;
                            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                                if (token == XContentParser.Token.FIELD_NAME) {
                                    currentFieldName = parser.currentName();
                                } else if (token == XContentParser.Token.VALUE_STRING) {
                                    if ("index".equals(currentFieldName)) {
                                        index = parser.text();
                                    } else if ("alias".equals(currentFieldName)) {
                                        alias = parser.text();
                                    } else if ("routing".equals(currentFieldName)) {
                                        routing = parser.textOrNull();
                                        routingSet = true;
                                    } else if ("indexRouting".equals(currentFieldName) || "index-routing".equals(currentFieldName) || "index_routing".equals(currentFieldName)) {
                                        indexRouting = parser.textOrNull();
                                        indexRoutingSet = true;
                                    } else if ("searchRouting".equals(currentFieldName) || "search-routing".equals(currentFieldName) || "search_routing".equals(currentFieldName)) {
                                        searchRouting = parser.textOrNull();
                                        searchRoutingSet = true;
                                    }
                                } else if (token == XContentParser.Token.START_OBJECT) {
                                    if ("filter".equals(currentFieldName)) {
                                        filter = parser.mapOrdered();
                                    }
                                }
                            }
                            if (index == null) {
                                throw new ElasticSearchIllegalArgumentException("Alias action [" + action + "] requires an [index] to be set");
                            }
                            if (alias == null) {
                                throw new ElasticSearchIllegalArgumentException("Alias action [" + action + "] requires an [alias] to be set");
                            }
                            if (type == AliasAction.Type.ADD) {
                                AliasAction aliasAction = newAddAliasAction(index, alias).filter(filter);
                                if (routingSet) {
                                    aliasAction.routing(routing);
                                }
                                if (indexRoutingSet) {
                                    aliasAction.indexRouting(indexRouting);
                                }
                                if (searchRoutingSet) {
                                    aliasAction.searchRouting(searchRouting);
                                }
                                indicesAliasesRequest.addAliasAction(aliasAction);
                            } else if (type == AliasAction.Type.REMOVE) {
                                indicesAliasesRequest.removeAlias(index, alias);
                            }
                        }
                    }
                }
            }
View Full Code Here

*/
@SuppressWarnings("unused")
public class UpdateIndicesAliasesRequestBuilder<JsonInput, JsonOutput> extends AbstractRequestBuilderJsonOutput<IndicesAliasesRequest, IndicesAliasesResponse, JsonInput, JsonOutput> {

    public UpdateIndicesAliasesRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
        super(client, new IndicesAliasesRequest(), jsonToString, stringToJson);
    }
View Full Code Here

    private void copyAliases(RestRequest request) {
        String index = request.param("index");
        String searchIndexName = request.param("searchIndex");
        IndexMetaData meta = client.admin().cluster().state(new ClusterStateRequest()).
                actionGet().getState().metaData().index(searchIndexName);
        IndicesAliasesRequest aReq = new IndicesAliasesRequest();
        boolean empty = true;
        if(meta != null && meta.aliases() != null) {
            for (ObjectCursor<String> oldAliasCursor : meta.aliases().keys() ) {
                empty = false;
                aReq.addAlias(index, oldAliasCursor.value);
            }
        }
        boolean aliasIncludeIndex = request.paramAsBoolean("addOldIndexAsAlias", false);
        if (aliasIncludeIndex) {
            if (client.admin().indices().exists(new IndicesExistsRequest(searchIndexName)).actionGet().isExists()) {
                logger.warn("Cannot add old index name (" + searchIndexName + ") as alias to index "
                        + index + " - as old index still exists");
            }
            else {
                aReq.addAlias(index, searchIndexName);
                empty = false;
            }
        }
        if(!empty) //!aReq.aliasActions().isEmpty())
            client.admin().indices().aliases(aReq).actionGet();
View Full Code Here

 
  // Add and remove aliases:
 
  public void createAlias(String sAliasName) {
    try {
      IndicesAliasesRequest iar = new IndicesAliasesRequest();
      IndicesAliasUtils.addAlias(iar, sAliasName, _sIndexName);
      _elasticClient.admin().indices().aliases(iar).actionGet();
    }
    catch (Exception e) {
      // Don't worry if this fails, probably just already exists
View Full Code Here

    }
  }//TESTED
 
  public void removeAlias(String sAliasName) {
    try {
      IndicesAliasesRequest iar = new IndicesAliasesRequest();
      IndicesAliasUtils.removeAlias(iar, sAliasName, _sIndexName);
      _elasticClient.admin().indices().aliases(iar).actionGet();
    }
    catch (Exception e) {
      // Don't worry if this fails, probably just doesn't exist
View Full Code Here

        client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();
    }

    public void addIndexAlias(String indexName, String alias) {
//        new AliasAction(AliasAction.Type.ADD, index, alias)
        client.admin().indices().aliases(new IndicesAliasesRequest().addAlias(indexName, alias)).actionGet();
    }
View Full Code Here

    }

    @Test
    public void testTableAlias() throws Exception {
        execute("create table terminator (model string, good boolean, actor object)");
        IndicesAliasesRequest request = new IndicesAliasesRequest();
        request.addAlias("entsafter", "terminator");
        client().admin().indices().aliases(request).actionGet();
        ensureGreen();

        TableInfo terminatorTable = referenceInfos.getTableInfo(new TableIdent(null, "terminator"));
        TableInfo entsafterTable = referenceInfos.getTableInfo(new TableIdent(null, "entsafter"));
View Full Code Here

    @Test
    public void testAliasPartitions() throws Exception {
        execute("create table terminator (model string, good boolean, actor object)");
        execute("create table transformer (model string, good boolean, actor object)");
        IndicesAliasesRequest request = new IndicesAliasesRequest();
        request.addAlias("entsafter", "terminator");
        request.addAlias("entsafter", "transformer");
        client().admin().indices().aliases(request).actionGet();
        ensureGreen();

        TableInfo entsafterTable = referenceInfos.getTableInfo(new TableIdent(null, "entsafter"));
        assertNotNull(entsafterTable);
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest$AliasActions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.