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;
}
Aggregations