use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacade method indexesExist.
private boolean indexesExist(List<Index> indexes) {
if (LOG.isTraceEnabled()) {
LOG.trace("Determining index(es) '{}' existence ...", toString(indexes));
}
String[] indexNames = toIndexNames(indexes);
IndicesExistsRequestBuilder indicesExistsRequest = client.admin().indices().prepareExists(indexNames);
IndicesExistsResponse indicesExistsResponse;
try {
indicesExistsResponse = indicesExistsRequest.get();
} catch (ElasticsearchException e) {
LOG.error("", e);
throw new IndexException(format("Error determining index(es) '%s' existence.", toString(indexes)));
}
boolean exists = indicesExistsResponse.isExists();
if (LOG.isDebugEnabled()) {
LOG.debug("Determined index(es) '{}' existence: {}.", toString(indexes), exists);
}
return exists;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacade method aggregate.
private Aggregations aggregate(List<AggregationBuilder> aggregations, QueryBuilder query, List<Index> indexes) {
if (LOG.isTraceEnabled()) {
if (query != null) {
LOG.trace("Aggregating docs in index(es) '{}' with aggregations '{}' and query '{}' ...", toString(indexes), aggregations, query);
} else {
LOG.trace("Aggregating docs in index(es) '{}' with aggregations '{}' ...", toString(indexes), aggregations);
}
}
SearchRequestBuilder searchRequest = createSearchRequest(query, null, 0, null, aggregations, 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 aggregating docs in index(es) '%s'.", toString(indexes)));
}
if (searchResponse.getFailedShards() > 0) {
LOG.error(stream(searchResponse.getShardFailures()).map(ShardSearchFailure::toString).collect(joining("\n")));
throw new IndexException(format("Error aggregating docs in index(es) '%s'.", toString(indexes)));
}
if (searchResponse.isTimedOut()) {
throw new IndexException(format("Timeout aggregating docs in index(es) '%s'.", toString(indexes)));
}
if (LOG.isDebugEnabled()) {
if (query != null) {
LOG.debug("Aggregated docs in index(es) '{}' with aggregations '{}' and query '{}' in {}ms.", toString(indexes), aggregations, query, searchResponse.getTookInMillis());
} else {
LOG.debug("Aggregated docs in index(es) '{}' with aggregations '{}' in {}ms.", toString(indexes), aggregations, searchResponse.getTookInMillis());
}
}
return searchResponse.getAggregations();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacade method index.
public void index(Index index, Document document) {
if (LOG.isTraceEnabled()) {
LOG.trace("Indexing doc with id '{}' in index '{}' ...", document.getId(), index.getName());
}
String indexName = index.getName();
String documentId = document.getId();
XContentBuilder source = document.getContent();
IndexRequestBuilder indexRequest = client.prepareIndex().setIndex(indexName).setType(indexName).setId(documentId).setSource(source);
IndexResponse indexResponse;
try {
indexResponse = indexRequest.get();
} catch (ResourceNotFoundException e) {
LOG.error("", e);
throw new UnknownIndexException(index.getName());
} catch (ElasticsearchException e) {
LOG.debug("", e);
throw new IndexException(format("Error indexing doc with id '%s' in index '%s'.", documentId, indexName));
}
// TODO: Is it good enough if at least one shard succeeds? Shouldn't we at least log something if failures > 0?
if (indexResponse.getShardInfo().getSuccessful() == 0) {
LOG.error(Arrays.stream(indexResponse.getShardInfo().getFailures()).map(ReplicationResponse.ShardInfo.Failure::toString).collect(joining("\n")));
throw new IndexException(format("Error indexing doc with id '%s' in index '%s'.", documentId, indexName));
}
if (LOG.isDebugEnabled()) {
LOG.debug("Indexed doc with id '{}' in index '{}'.", documentId, indexName);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacadeTest method testRefreshIndicesThrowsException.
@Test(expectedExceptions = IndexException.class, expectedExceptionsMessageRegExp = "Error refreshing index\\(es\\) '_all'\\.")
public void testRefreshIndicesThrowsException() {
when(indicesAdminClient.prepareRefresh("_all")).thenReturn(refreshRequestBuilder);
when(refreshRequestBuilder.get()).thenThrow(new ElasticsearchException("exception"));
clientFacade.refreshIndexes();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacadeTest method testCloseThrowsException.
@Test
public void testCloseThrowsException() throws Exception {
doThrow(new ElasticsearchException("exception")).when(client).close();
clientFacade.close();
verify(mockAppender).doAppend(matcher(ERROR, "Error closing Elasticsearch client"));
}
Aggregations