Search in sources :

Example 86 with ElasticsearchException

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));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 87 with ElasticsearchException

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);
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 88 with ElasticsearchException

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;
}
Also used : ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 89 with ElasticsearchException

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);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) ElasticSearchException(org.elasticsearch.ElasticSearchException) HashSet(java.util.HashSet) TridentTuple(storm.trident.tuple.TridentTuple)

Example 90 with ElasticsearchException

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");
}
Also used : ProtobufSystemInfo(org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo) ElasticsearchException(org.elasticsearch.ElasticsearchException) EsClient(org.sonar.server.es.EsClient) Test(org.junit.Test)

Aggregations

ElasticsearchException (org.elasticsearch.ElasticsearchException)310 IOException (java.io.IOException)128 Settings (org.elasticsearch.common.settings.Settings)32 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)30 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)30 ClusterState (org.elasticsearch.cluster.ClusterState)29 Matchers.containsString (org.hamcrest.Matchers.containsString)25 List (java.util.List)23 Map (java.util.Map)22 AtomicReference (java.util.concurrent.atomic.AtomicReference)20 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)18 XContentParser (org.elasticsearch.common.xcontent.XContentParser)17 Path (java.nio.file.Path)16 Test (org.junit.Test)16 ActionListener (org.elasticsearch.action.ActionListener)15 Collections (java.util.Collections)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Version (org.elasticsearch.Version)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13