use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacadeTest method testSearchThrowsException.
@Test(expectedExceptions = IndexException.class, expectedExceptionsMessageRegExp = "Error searching docs in index\\(es\\) 'index' with query 'a == b'\\.")
public void testSearchThrowsException() {
Index index = Index.create("index");
when(client.prepareSearch("index")).thenReturn(searchRequestBuilder);
when(searchRequestBuilder.get()).thenThrow(new ElasticsearchException("Exception"));
when(queryBuilder.toString()).thenReturn("a == b");
clientFacade.search(queryBuilder, 0, 100, ImmutableList.of(index));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project molgenis by molgenis.
the class ClientFacadeTest method testAggregateThrowsException.
@Test(expectedExceptions = IndexException.class, expectedExceptionsMessageRegExp = "Error aggregating docs in index\\(es\\) 'index'\\.")
public void testAggregateThrowsException() {
Index index = Index.create("index");
when(client.prepareSearch("index")).thenReturn(searchRequestBuilder);
when(searchRequestBuilder.get()).thenThrow(new ElasticsearchException("Exception"));
when(queryBuilder.toString()).thenReturn("a == b");
clientFacade.aggregate(ImmutableList.of(aggregationBuilder), queryBuilder, index);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project pentaho-kettle by pentaho.
the class ElasticSearchBulk method processBatch.
private boolean processBatch(boolean makeNew) throws KettleStepException {
ActionFuture<BulkResponse> actionFuture = currentRequest.execute();
boolean responseOk = false;
BulkResponse response = null;
try {
if (timeout != null && timeoutUnit != null) {
response = actionFuture.actionGet(timeout, timeoutUnit);
} else {
response = actionFuture.actionGet();
}
} catch (ElasticsearchException e) {
String msg = BaseMessages.getString(PKG, "ElasticSearchBulk.Error.BatchExecuteFail", e.getLocalizedMessage());
if (e instanceof ElasticsearchTimeoutException) {
msg = BaseMessages.getString(PKG, "ElasticSearchBulk.Error.Timeout");
}
logError(msg);
rejectAllRows(msg);
}
if (response != null) {
responseOk = handleResponse(response);
requestsBuffer.clear();
} else {
// have to assume all failed
numberOfErrors += currentRequest.numberOfActions();
setErrors(numberOfErrors);
}
if (makeNew) {
currentRequest = client.prepareBulk();
data.nextBufferRowIdx = 0;
data.inputRowBuffer = new Object[batchSize][];
} else {
currentRequest = null;
data.inputRowBuffer = null;
}
return responseOk;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project storm-elastic-search by hmsonline.
the class ElasticSearchState method createIndices.
public void createIndices(TridentElasticSearchMapper mapper, List<TridentTuple> tuples) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
Set<String> existingIndex = new HashSet<String>();
for (TridentTuple tuple : tuples) {
String indexName = mapper.mapToIndex(tuple);
String type = mapper.mapToType(tuple);
String key = mapper.mapToKey(tuple);
Map<String, Object> data = mapper.mapToData(tuple);
String parentId = mapper.mapToParentId(tuple);
if (!existingIndex.contains(indexName) && !client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet().isExists()) {
createIndex(bulkRequest, indexName, mapper.mapToIndexSettings(tuple));
createMapping(bulkRequest, indexName, type, mapper.mapToMappingSettings(tuple));
existingIndex.add(indexName);
}
if (StringUtils.isBlank(parentId)) {
bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data));
} else {
LOGGER.debug("parent: " + parentId);
bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data).setParent(parentId));
}
}
try {
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
// Index failed. Retry!
throw new FailedException("Cannot create index via ES: " + bulkResponse.buildFailureMessage());
}
} catch (ElasticSearchException e) {
StormElasticSearchUtils.handleElasticSearchException(getClass(), e);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException in project sonarqube by SonarSource.
the class EsStateSectionTest method attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails.
@Test
public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() {
EsClient esClientMock = mock(EsClient.class);
EsStateSection underTest = new EsStateSection(esClientMock);
when(esClientMock.clusterHealth(any())).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message")));
ProtobufSystemInfo.Section section = underTest.toProtobuf();
assertThatAttributeIs(section, "State", "some cause message");
}
Aggregations