Search in sources :

Example 1 with AliasAction

use of org.springframework.data.elasticsearch.core.index.AliasAction in project spring-data-elasticsearch by spring-projects.

the class RequestFactory method indicesAliasesRequest.

public IndicesAliasesRequest indicesAliasesRequest(AliasActions aliasActions) {
    IndicesAliasesRequest request = new IndicesAliasesRequest();
    aliasActions.getActions().forEach(aliasAction -> {
        IndicesAliasesRequest.AliasActions aliasActionsES = null;
        if (aliasAction instanceof AliasAction.Add) {
            AliasAction.Add add = (AliasAction.Add) aliasAction;
            IndicesAliasesRequest.AliasActions addES = IndicesAliasesRequest.AliasActions.add();
            AliasActionParameters parameters = add.getParameters();
            addES.indices(parameters.getIndices());
            addES.aliases(parameters.getAliases());
            addES.routing(parameters.getRouting());
            addES.indexRouting(parameters.getIndexRouting());
            addES.searchRouting(parameters.getSearchRouting());
            addES.isHidden(parameters.getHidden());
            addES.writeIndex(parameters.getWriteIndex());
            Query filterQuery = parameters.getFilterQuery();
            if (filterQuery != null) {
                elasticsearchConverter.updateQuery(filterQuery, parameters.getFilterQueryClass());
                QueryBuilder queryBuilder = getFilter(filterQuery);
                if (queryBuilder == null) {
                    queryBuilder = getQuery(filterQuery);
                }
                addES.filter(queryBuilder);
            }
            aliasActionsES = addES;
        } else if (aliasAction instanceof AliasAction.Remove) {
            AliasAction.Remove remove = (AliasAction.Remove) aliasAction;
            IndicesAliasesRequest.AliasActions removeES = IndicesAliasesRequest.AliasActions.remove();
            AliasActionParameters parameters = remove.getParameters();
            removeES.indices(parameters.getIndices());
            removeES.aliases(parameters.getAliases());
            aliasActionsES = removeES;
        } else if (aliasAction instanceof AliasAction.RemoveIndex) {
            AliasAction.RemoveIndex removeIndex = (AliasAction.RemoveIndex) aliasAction;
            IndicesAliasesRequest.AliasActions removeIndexES = IndicesAliasesRequest.AliasActions.removeIndex();
            AliasActionParameters parameters = removeIndex.getParameters();
            removeIndexES.indices(parameters.getIndices()[0]);
            aliasActionsES = removeIndexES;
        }
        if (aliasActionsES != null) {
            request.addAliasAction(aliasActionsES);
        }
    });
    return request;
}
Also used : MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) AliasActionParameters(org.springframework.data.elasticsearch.core.index.AliasActionParameters)

Aggregations

IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)1 MoreLikeThisQueryBuilder (org.elasticsearch.index.query.MoreLikeThisQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 AliasAction (org.springframework.data.elasticsearch.core.index.AliasAction)1 AliasActionParameters (org.springframework.data.elasticsearch.core.index.AliasActionParameters)1 AliasActions (org.springframework.data.elasticsearch.core.index.AliasActions)1