Java Code Examples for org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder#removeAlias()

The following examples show how to use org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder#removeAlias() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchUpdaterImpl.java    From stash-codesearch-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Makes one alias point to another's index, deleting the old index afterwards. Returns true
 * iff the operation was successful.
 */
private synchronized boolean redirectAndDeleteAliasedIndex(String fromAlias, String toAlias) {
    // Find indices corresponding to aliases
    String fromIndex = getIndexFromAlias(fromAlias);
    String toIndex = getIndexFromAlias(toAlias);

    if (toIndex == null) {
        log.error("{} does not resolve to an index", toAlias);
        return false;
    }

    if (toIndex.equals(fromIndex)) {
        log.warn("{} and {} resolve to the same index", fromAlias, toAlias);
        return false;
    }

    // Perform alias switch
    IndicesAliasesRequestBuilder builder = es.getClient().admin().indices().prepareAliases();
    if (fromIndex != null) {
        builder.removeAlias(fromIndex, fromAlias);
    }
    builder.addAlias(toIndex, fromAlias).get();

    // Delete old index
    if (fromIndex != null) {
        es.getClient().admin().indices().prepareDelete(fromIndex).get();
    }

    return true;
}
 
Example 2
Source File: EsEntityIndexImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private void addAlias(String indexName) {
    Timer.Context timer = updateAliasTimer.time();
    try {
        Boolean isAck;

        final AdminClient adminClient = esProvider.getClient().admin();

        String[] indexNames = getIndexes(AliasType.Write);

        int count = 0;
        IndicesAliasesRequestBuilder aliasesRequestBuilder = adminClient.indices().prepareAliases();
        for (String currentIndex : indexNames) {
            aliasesRequestBuilder.removeAlias(currentIndex, alias.getWriteAlias());
            count++;
        }
        if (count > 0) {
            isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
            logger.info("Removed Index Name from Alias=[{}] ACK=[{}]", alias, isAck);
        }
        aliasesRequestBuilder = adminClient.indices().prepareAliases();
        //Added For Graphite Metrics
        //add write alias
        aliasesRequestBuilder.addAlias(indexName, alias.getWriteAlias());
        //Added For Graphite Metrics
        // add read alias
        aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias());

        isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
        logger.info("Created new read and write aliases ACK=[{}]", isAck);
        aliasCache.invalidate(alias);

    } catch (Exception e) {
        logger.warn("Failed to create alias ", e);
    } finally {
        timer.stop();
    }
}