use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method setAlias.
@Override
public int setAlias(final String index, final String alias) throws CalFacadeException {
// IndicesAliasesResponse resp = null;
try {
/* Other is the alias name - index is the index we were just indexing into
*/
final IndicesAdminClient idx = getAdminIdx();
final GetAliasesRequestBuilder igarb = idx.prepareGetAliases(alias);
final ActionFuture<GetAliasesResponse> getAliasesAf = idx.getAliases(igarb.request());
final GetAliasesResponse garesp = getAliasesAf.actionGet();
final ImmutableOpenMap<String, List<AliasMetaData>> aliasesmeta = garesp.getAliases();
final IndicesAliasesRequestBuilder iarb = idx.prepareAliases();
final Iterator<String> it = aliasesmeta.keysIt();
while (it.hasNext()) {
final String indexName = it.next();
for (final AliasMetaData amd : aliasesmeta.get(indexName)) {
if (amd.getAlias().equals(alias)) {
iarb.removeAlias(indexName, alias);
}
}
}
iarb.addAlias(index, alias);
final ActionFuture<IndicesAliasesResponse> af = idx.aliases(iarb.request());
/*resp = */
af.actionGet();
return 0;
} catch (final ElasticsearchException ese) {
// Failed somehow
error(ese);
return -1;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations