use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.
the class IndexedRepositoryDecoratorTest method aggregateUnknownIndexExceptionUnrecoverable.
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Error executing query, index for entity type 'My entity type' with id 'entity' does not exist")
public void aggregateUnknownIndexExceptionUnrecoverable() {
AggregateQuery aggregateQuery = mock(AggregateQuery.class);
when(searchService.aggregate(repositoryEntityType, aggregateQuery)).thenThrow(new UnknownIndexException("msg"));
indexedRepositoryDecorator.aggregate(aggregateQuery);
}
use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.
the class IndexedRepositoryDecoratorTest method aggregateUnknownIndexExceptionRecoverable.
@Test
public void aggregateUnknownIndexExceptionRecoverable() {
AggregateQuery aggregateQuery = mock(AggregateQuery.class);
AggregateResult aggregateResult = mock(AggregateResult.class);
when(searchService.aggregate(repositoryEntityType, aggregateQuery)).thenThrow(new UnknownIndexException("msg")).thenReturn(aggregateResult);
assertEquals(indexedRepositoryDecorator.aggregate(aggregateQuery), aggregateResult);
verify(delegateRepository, never()).count(unsupportedQuery);
}
use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.
the class IndexedRepositoryDecoratorTest method findAllUnknownIndexExceptionUnrecoverable.
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Error executing query, index for entity type 'My entity type' with id 'entity' does not exist")
public void findAllUnknownIndexExceptionUnrecoverable() {
when(searchService.search(repositoryEntityType, unsupportedQuery)).thenThrow(new UnknownIndexException("msg"));
indexedRepositoryDecorator.findAll(unsupportedQuery);
}
use of org.molgenis.data.index.exception.UnknownIndexException 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.UnknownIndexException 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);
}
Aggregations