Search in sources :

Example 1 with GetAliasesRequestBuilder

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);
    }
}
Also used : GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) GetAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ElasticsearchException(org.elasticsearch.ElasticsearchException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) ArrayList(java.util.ArrayList) List(java.util.List) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) IndicesAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 IndicesAliasesRequestBuilder (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder)1 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)1 GetAliasesRequestBuilder (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder)1 GetAliasesResponse (org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)1 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)1 AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)1