Search in sources :

Example 6 with IndexException

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

the class ClientFacade method deleteIndexes.

private void deleteIndexes(List<Index> indexes) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Deleting index(es) '{}' ...", toString(indexes));
    }
    String[] indexNames = toIndexNames(indexes);
    DeleteIndexRequestBuilder deleteIndexRequest = client.admin().indices().prepareDelete(indexNames);
    DeleteIndexResponse deleteIndexResponse;
    try {
        deleteIndexResponse = deleteIndexRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.debug("", e);
        throw new UnknownIndexException(toString(indexes));
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error deleting index(es) '%s'.", toString(indexes)));
    }
    if (!deleteIndexResponse.isAcknowledged()) {
        throw new IndexException(format("Error deleting index(es) '%s'.", toString(indexes)));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleted index(es) '{}'.", toString(indexes));
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) DeleteIndexRequestBuilder(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 7 with IndexException

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

the class ClientFacade method explain.

public Explanation explain(SearchHit searchHit, QueryBuilder query) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Explaining doc with id '{}' in index '{}' for query '{}' ...", searchHit.getId(), searchHit.getIndex(), query);
    }
    String indexName = searchHit.getIndex();
    // FIXME: ClientFacade shouldn't assume that typename equals typename
    ExplainRequestBuilder explainRequestBuilder = client.prepareExplain(indexName, indexName, searchHit.getId()).setQuery(query);
    ExplainResponse explainResponse;
    try {
        explainResponse = explainRequestBuilder.get();
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error explaining doc with id '%s' in index '%s' for query '%s'.", searchHit.getId(), searchHit.getIndex(), query));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Explained doc with id '{}' in index '{}' for query.", searchHit.getId(), searchHit.getIndex(), query);
    }
    return explainResponse.getExplanation();
}
Also used : IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) ExplainResponse(org.elasticsearch.action.explain.ExplainResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) ExplainRequestBuilder(org.elasticsearch.action.explain.ExplainRequestBuilder)

Example 8 with IndexException

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

the class ClientFacade method search.

private SearchHits search(QueryBuilder query, int from, int size, Sort sort, List<Index> indexes) {
    if (size > 10000) {
        throw new MolgenisQueryException(String.format("Batch size of %s exceeds the maximum batch size of %s for search queries", size, MAX_BATCH_SIZE));
    }
    if (LOG.isTraceEnabled()) {
        if (sort != null) {
            LOG.trace("Searching docs [{}-{}] in index(es) '{}' with query '{}' sorted by '{}' ...", from, from + size, toString(indexes), query, sort);
        } else {
            LOG.trace("Searching docs [{}-{}] in index(es) '{}' with query '{}' ...", from, from + size, toString(indexes), query);
        }
    }
    SearchRequestBuilder searchRequest = createSearchRequest(query, from, size, sort, null, indexes);
    SearchResponse searchResponse;
    try {
        searchResponse = searchRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.error("", e);
        throw new UnknownIndexException(toIndexNames(indexes));
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error searching docs in index(es) '%s' with query '%s'.", toString(indexes), query));
    }
    if (searchResponse.getFailedShards() > 0) {
        LOG.error(stream(searchResponse.getShardFailures()).map(ShardSearchFailure::toString).collect(joining("\n")));
        throw new IndexException(format("Error searching docs in index(es) '%s' with query '%s'.", toString(indexes), query));
    }
    if (searchResponse.isTimedOut()) {
        throw new IndexException(format("Timeout searching counting docs in index(es) '%s'  with query '%s'.", toString(indexes), query));
    }
    if (LOG.isDebugEnabled()) {
        if (sort != null) {
            LOG.debug("Searched {} docs in index(es) '{}' with query '{}' sorted by '{}' in {}ms.", searchResponse.getHits().getTotalHits(), toString(indexes), query, sort, searchResponse.getTookInMillis());
        } else {
            LOG.debug("Searched {} docs in index(es) '{}' with query '{}' in {}ms.", searchResponse.getHits().getTotalHits(), toString(indexes), query, searchResponse.getTookInMillis());
        }
    }
    return createSearchResponse(searchResponse);
}
Also used : MolgenisQueryException(org.molgenis.data.MolgenisQueryException) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) 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) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 9 with IndexException

use of org.molgenis.data.index.exception.IndexException 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)

Example 10 with IndexException

use of org.molgenis.data.index.exception.IndexException 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)

Aggregations

IndexException (org.molgenis.data.index.exception.IndexException)11 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)11 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)7 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)2 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)2 DeleteIndexRequestBuilder (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder)2 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)1 IndicesExistsRequestBuilder (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder)1 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)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