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));
}
}
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();
}
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);
}
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());
}
}
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());
}
}
Aggregations