Search in sources :

Example 1 with IndexAlreadyExistsException

use of org.molgenis.data.index.exception.IndexAlreadyExistsException in project molgenis by molgenis.

the class ClientFacade method createIndex.

public void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Creating index '{}' ...", index.getName());
    }
    CreateIndexRequestBuilder createIndexRequest = createIndexRequest(index, indexSettings, mappingStream);
    CreateIndexResponse createIndexResponse;
    try {
        createIndexResponse = createIndexRequest.get();
    } catch (ResourceAlreadyExistsException e) {
        LOG.debug("", e);
        throw new IndexAlreadyExistsException(index.getName());
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error creating index '%s'.", index.getName()));
    }
    // 'acknowledged' indicates whether the index was successfully created in the cluster before the request timeout
    if (!createIndexResponse.isAcknowledged()) {
        LOG.warn("Index '{}' creation possibly failed (acknowledged=false)", index.getName());
    }
    // 'shards_acknowledged' indicates whether the requisite number of shard copies were started for each shard in the index before timing out
    if (!createIndexResponse.isShardsAcked()) {
        LOG.warn("Index '{}' creation possibly failed (shards_acknowledged=false)", index.getName());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created index '{}'.", index.getName());
    }
}
Also used : IndexAlreadyExistsException(org.molgenis.data.index.exception.IndexAlreadyExistsException) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchException(org.elasticsearch.ElasticsearchException) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Aggregations

ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)1 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 IndexAlreadyExistsException (org.molgenis.data.index.exception.IndexAlreadyExistsException)1 IndexException (org.molgenis.data.index.exception.IndexException)1 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)1