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

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


     * 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


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

    @Override
    public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
        IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
        indicesAliasesRequest.listenerThreaded(false);
        indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
        try (XContentParser parser = XContentFactory.xContent(request.content()).createParser(request.content())) {
            // {
            //     actions : [
            //         { add : { index : "test1", alias : "alias1", filter : {"user" : "kimchy"} } }
            //         { remove : { index : "test1", alias : "alias1" } }
            //     ]
            // }
            indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
            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.isValue()) {
                                    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 (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

                    }
                }
            }
        }

        IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
        indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
        String[] aliases = new String[]{alias};
        IndicesAliasesRequest.AliasActions aliasAction = new AliasActions(AliasAction.Type.ADD, indices, aliases);
        indicesAliasesRequest.addAliasAction(aliasAction);
        indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));


        if (routing != null) {
            aliasAction.routing(routing);
        }
View Full Code Here

    @Override
    public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
        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.removeAlias(indices, aliases);
        indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));

        client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<IndicesAliasesResponse>(channel));
    }
View Full Code Here

TOP

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

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.