if (currentState.metaData().hasIndex(aliasAction.alias())) {
listener.onFailure(new InvalidAliasNameException(new Index(aliasAction.index()), aliasAction.alias(), "an index exists with the same name as the alias"));
return currentState;
}
if (aliasAction.indexRouting() != null && aliasAction.indexRouting().indexOf(',') != -1) {
listener.onFailure(new ElasticSearchIllegalArgumentException("alias [" + aliasAction.alias() + "] has several routing values associated with it"));
return currentState;
}
}
List<String> indicesToClose = Lists.newArrayList();
Map<String, IndexService> indices = Maps.newHashMap();
try {
boolean changed = false;
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
for (AliasAction aliasAction : request.actions) {
IndexMetaData indexMetaData = builder.get(aliasAction.index());
if (indexMetaData == null) {
throw new IndexMissingException(new Index(aliasAction.index()));
}
IndexMetaData.Builder indexMetaDataBuilder = newIndexMetaDataBuilder(indexMetaData);
if (aliasAction.actionType() == AliasAction.Type.ADD) {
String filter = aliasAction.filter();
if (Strings.hasLength(filter)) {
// parse the filter, in order to validate it
IndexService indexService = indices.get(indexMetaData.index());
if (indexService == null) {
indexService = indicesService.indexService(indexMetaData.index());
if (indexService == null) {
// temporarily create the index so we have can parse the filter
indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), currentState.nodes().localNode().id());
indicesToClose.add(indexMetaData.index());
}
indices.put(indexMetaData.index(), indexService);
}
// now, parse the filter
IndexQueryParserService indexQueryParser = indexService.queryParserService();
try {
XContentParser parser = XContentFactory.xContent(filter).createParser(filter);
try {
indexQueryParser.parseInnerFilter(parser);
} finally {
parser.close();
}
} catch (Exception e) {
listener.onFailure(new ElasticSearchIllegalArgumentException("failed to parse filter for [" + aliasAction.alias() + "]", e));
return currentState;
}
}
AliasMetaData newAliasMd = AliasMetaData.newAliasMetaDataBuilder(
aliasAction.alias())