Search in sources :

Example 11 with UnknownIndexException

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

the class ClientFacade method deleteById.

public void deleteById(Index index, Document document) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Deleting doc with id '{}' in index '{}' ...", document.getId(), index.getName());
    }
    String indexName = index.getName();
    String documentId = document.getId();
    DeleteRequestBuilder deleteRequest = client.prepareDelete().setIndex(indexName).setType(indexName).setId(documentId);
    DeleteResponse deleteResponse;
    try {
        deleteResponse = deleteRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.error("", e);
        throw new UnknownIndexException(index.getName());
    } catch (ElasticsearchException e) {
        LOG.debug("", e);
        throw new IndexException(format("Error deleting doc with id '%s' in index '%s'.", documentId, indexName));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleted doc with id '{}' in index '{}' and status '{}'", documentId, indexName, deleteResponse.getResult());
    }
}
Also used : DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 12 with UnknownIndexException

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

the class ClientFacade method refreshIndexes.

private void refreshIndexes(List<Index> indexes) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Refreshing index(es) '{}' ...", toString(indexes));
    }
    String[] indexNames = toIndexNames(indexes);
    RefreshRequestBuilder refreshRequest = client.admin().indices().prepareRefresh(indexNames);
    RefreshResponse refreshResponse;
    try {
        refreshResponse = refreshRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.debug("", e);
        throw new UnknownIndexException(toIndexNames(indexes));
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error refreshing index(es) '%s'.", toString(indexes)));
    }
    if (refreshResponse.getFailedShards() > 0) {
        LOG.error(stream(refreshResponse.getShardFailures()).map(ShardOperationFailedException::toString).collect(joining("\n")));
        throw new IndexException(format("Error refreshing index(es) '%s'.", toString(indexes)));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Refreshed index(es) '{}'", toString(indexes));
    }
}
Also used : RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) RefreshRequestBuilder(org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder)

Aggregations

UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)7 IndexException (org.molgenis.data.index.exception.IndexException)7 Test (org.testng.annotations.Test)5 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 DeleteIndexRequestBuilder (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder)2 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)2 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)2 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)1 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 RefreshRequestBuilder (org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1