org.elasticsearch.cluster.metadata.AliasAction Java Examples

The following examples show how to use org.elasticsearch.cluster.metadata.AliasAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShellScope.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new <code>ShellScope</code> given the actual scope object
 * @param scope the actual scope object that depends on the engine in use
 */
ShellScope(Scope scope, ResourceRegistry resourceRegistry) {
    this.scope = scope;
    this.resourceRegistry = resourceRegistry;
    registerJavaClass(Requests.class);
    registerJavaClass(SearchSourceBuilder.class);
    registerJavaClass(QueryBuilders.class);
    registerJavaClass(FilterBuilders.class);
    registerJavaClass(SortBuilders.class);
    registerJavaClass(FacetBuilders.class);
    registerJavaClass(RescoreBuilder.class);
    registerJavaClass(SuggestBuilder.class);
    registerJavaClass(AliasAction.class);
    registerJavaClass(HttpParameters.class);
    registerJavaClass(AllocateAllocationCommand.class);
    registerJavaClass(CancelAllocationCommand.class);
    registerJavaClass(MoveAllocationCommand.class);
    registerJavaClass(ShardId.class);
}
 
Example #2
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AliasActions(Type type, String index, String[] aliases) {
    aliasAction = new AliasAction(type);
    indices(index);
    aliases(aliases);
}
 
Example #3
Source File: UpdateIndicesAliasesRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public UpdateIndicesAliasesRequestBuilder<JsonInput, JsonOutput> addAliasAction(AliasAction aliasAction) {
    request.addAliasAction(aliasAction);
    return this;
}
 
Example #4
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public IndicesAliasesRequest addAliasAction(AliasAction action) {
    addAliasAction(new AliasActions(action));
    return this;
}
 
Example #5
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AliasAction aliasAction() {
    return aliasAction;
}
 
Example #6
Source File: RestIndexPutAliasAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    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 = XContentFactory.xContent(request.content()).createParser(request.content())) {
            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()));
    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);
    }
    if (searchRouting != null) {
        aliasAction.searchRouting(searchRouting);
    }
    if (indexRouting != null) {
        aliasAction.indexRouting(indexRouting);
    }
    if (filter != null) {
        aliasAction.filter(filter);
    }
    client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<IndicesAliasesResponse>(channel));
}
 
Example #7
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AliasActions(AliasAction action) {
    this.aliasAction = action;
    indices(action.index());
    aliases(action.alias());
}
 
Example #8
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
AliasActions(AliasAction.Type type, String[] index, String alias) {
    aliasAction = new AliasAction(type);
    indices(index);
    aliases(alias);
}
 
Example #9
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AliasActions(AliasAction.Type type, String index, String alias) {
    aliasAction = new AliasAction(type);
    indices(index);
    aliases(alias);
}
 
Example #10
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AliasActions(AliasAction.Type type, String[] indices, String[] aliases) {
    aliasAction = new AliasAction(type);
    indices(indices);
    aliases(aliases);
}
 
Example #11
Source File: TransportIndicesAliasesAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void masterOperation(final IndicesAliasesRequest request, final ClusterState state, final ActionListener<IndicesAliasesResponse> listener) {

    //Expand the indices names
    List<AliasActions> actions = request.aliasActions();
    List<AliasAction> finalActions = new ArrayList<>();
    boolean hasOnlyDeletesButNoneCanBeDone = true;
    Set<String> aliases = new HashSet<>();
    for (AliasActions action : actions) {
        //expand indices
        String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request.indicesOptions(), action.indices());
        //collect the aliases
        Collections.addAll(aliases, action.aliases());
        for (String index : concreteIndices) {
            for (String alias : action.concreteAliases(state.metaData(), index)) { 
                AliasAction finalAction = new AliasAction(action.aliasAction());
                finalAction.index(index);
                finalAction.alias(alias);
                finalActions.add(finalAction);
                //if there is only delete requests, none will be added if the types do not map to any existing type
                hasOnlyDeletesButNoneCanBeDone = false;
            }
        }
    }
    if (hasOnlyDeletesButNoneCanBeDone && actions.size() != 0) {
        throw new AliasesNotFoundException(aliases.toArray(new String[aliases.size()]));
    }
    request.aliasActions().clear();
    IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest()
            .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
            .actions(finalActions.toArray(new AliasAction[finalActions.size()]));

    indexAliasesService.indicesAliases(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {
        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new IndicesAliasesResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Throwable t) {
            logger.debug("failed to perform aliases", t);
            listener.onFailure(t);
        }
    });
}
 
Example #12
Source File: IndicesAliasesClusterStateUpdateRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the alias actions to be performed
 */
public AliasAction[] actions() {
    return actions;
}
 
Example #13
Source File: IndicesAliasesRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds an alias action to the request.
 *
 * @param aliasAction The alias action
 */
public IndicesAliasesRequestBuilder addAliasAction(AliasAction aliasAction) {
    request.addAliasAction(aliasAction);
    return this;
}
 
Example #14
Source File: IndicesAliasesRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds an alias to the index.
 *
 * @param indices The indices
 * @param alias   The alias
 * @param filter  The filter
 */
public IndicesAliasesRequestBuilder addAlias(String indices[], String alias, String filter) {
    AliasActions action = new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filter);
    request.addAliasAction(action);
    return this;
}
 
Example #15
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds an alias to the index.
 * @param alias The alias
 * @param indices The indices
 */
public IndicesAliasesRequest addAlias(String alias, String... indices) {
    addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias));
    return this;
}
 
Example #16
Source File: IndicesAliasesRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds an alias to the index.
 *
 * @param index  The index
 * @param alias  The alias
 * @param filter The filter
 */
public IndicesAliasesRequestBuilder addAlias(String index, String alias, String filter) {
    AliasActions action = new AliasActions(AliasAction.Type.ADD, index, alias).filter(filter);
    request.addAliasAction(action);
    return this;
}
 
Example #17
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds an alias to the index.
 * @param alias  The alias
 * @param filter The filter
 * @param indices  The indices
 */
public IndicesAliasesRequest addAlias(String alias, Map<String, Object> filter, String... indices) {
    addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filter));
    return this;
}
 
Example #18
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds an alias to the index.
 * @param alias         The alias
 * @param filterBuilder The filter
 * @param indices         The indices
 */
public IndicesAliasesRequest addAlias(String alias, QueryBuilder filterBuilder, String... indices) {
    addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filterBuilder));
    return this;
}
 
Example #19
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Removes an alias to the index.
 *
 * @param indices The indices
 * @param aliases The aliases
 */
public IndicesAliasesRequest removeAlias(String[] indices, String... aliases) {
    addAliasAction(new AliasActions(AliasAction.Type.REMOVE, indices, aliases));
    return this;
}
 
Example #20
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Removes an alias to the index.
 *
 * @param index The index
 * @param aliases The aliases
 */
public IndicesAliasesRequest removeAlias(String index, String... aliases) {
    addAliasAction(new AliasActions(AliasAction.Type.REMOVE, index, aliases));
    return this;
}