Search in sources :

Example 6 with Failure

use of org.elasticsearch.action.bulk.BulkItemResponse.Failure in project elasticsearch by elastic.

the class AsyncBulkByScrollActionTests method testBulkFailuresAbortRequest.

/**
     * Mimicks bulk indexing failures.
     */
public void testBulkFailuresAbortRequest() throws Exception {
    Failure failure = new Failure("index", "type", "id", new RuntimeException("test"));
    DummyAsyncBulkByScrollAction action = new DummyAsyncBulkByScrollAction();
    BulkResponse bulkResponse = new BulkResponse(new BulkItemResponse[] { new BulkItemResponse(0, DocWriteRequest.OpType.CREATE, failure) }, randomLong());
    action.onBulkResponse(timeValueNanos(System.nanoTime()), bulkResponse);
    BulkByScrollResponse response = listener.get();
    assertThat(response.getBulkFailures(), contains(failure));
    assertThat(response.getSearchFailures(), empty());
    assertNull(response.getReasonCancelled());
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)

Example 7 with Failure

use of org.elasticsearch.action.bulk.BulkItemResponse.Failure in project elasticsearch by elastic.

the class BulkByScrollResponseTests method assertResponseEquals.

private void assertResponseEquals(BulkByScrollResponse expected, BulkByScrollResponse actual) {
    assertEquals(expected.getTook(), actual.getTook());
    BulkByScrollTaskStatusTests.assertTaskStatusEquals(Version.CURRENT, expected.getStatus(), actual.getStatus());
    assertEquals(expected.getBulkFailures().size(), actual.getBulkFailures().size());
    for (int i = 0; i < expected.getBulkFailures().size(); i++) {
        Failure expectedFailure = expected.getBulkFailures().get(i);
        Failure actualFailure = actual.getBulkFailures().get(i);
        assertEquals(expectedFailure.getIndex(), actualFailure.getIndex());
        assertEquals(expectedFailure.getType(), actualFailure.getType());
        assertEquals(expectedFailure.getId(), actualFailure.getId());
        assertEquals(expectedFailure.getMessage(), actualFailure.getMessage());
        assertEquals(expectedFailure.getStatus(), actualFailure.getStatus());
    }
    assertEquals(expected.getSearchFailures().size(), actual.getSearchFailures().size());
    for (int i = 0; i < expected.getSearchFailures().size(); i++) {
        SearchFailure expectedFailure = expected.getSearchFailures().get(i);
        SearchFailure actualFailure = actual.getSearchFailures().get(i);
        assertEquals(expectedFailure.getIndex(), actualFailure.getIndex());
        assertEquals(expectedFailure.getShardId(), actualFailure.getShardId());
        assertEquals(expectedFailure.getNodeId(), actualFailure.getNodeId());
        assertEquals(expectedFailure.getReason().getClass(), actualFailure.getReason().getClass());
        assertEquals(expectedFailure.getReason().getMessage(), actualFailure.getReason().getMessage());
    }
}
Also used : SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure)

Example 8 with Failure

use of org.elasticsearch.action.bulk.BulkItemResponse.Failure in project elasticsearch by elastic.

the class BulkItemResponseTests method testFailureToAndFromXContent.

public void testFailureToAndFromXContent() throws IOException {
    final XContentType xContentType = randomFrom(XContentType.values());
    int itemId = randomIntBetween(0, 100);
    String index = randomAsciiOfLength(5);
    String type = randomAsciiOfLength(5);
    String id = randomAsciiOfLength(5);
    DocWriteRequest.OpType opType = randomFrom(DocWriteRequest.OpType.values());
    final Tuple<Throwable, ElasticsearchException> exceptions = randomExceptions();
    Exception bulkItemCause = (Exception) exceptions.v1();
    Failure bulkItemFailure = new Failure(index, type, id, bulkItemCause);
    BulkItemResponse bulkItemResponse = new BulkItemResponse(itemId, opType, bulkItemFailure);
    Failure expectedBulkItemFailure = new Failure(index, type, id, exceptions.v2(), ExceptionsHelper.status(bulkItemCause));
    BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(itemId, opType, expectedBulkItemFailure);
    BytesReference originalBytes = toXContent(bulkItemResponse, xContentType, randomBoolean());
    // Shuffle the XContent fields
    if (randomBoolean()) {
        try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
            originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
        }
    }
    BulkItemResponse parsedBulkItemResponse;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
        parsedBulkItemResponse = BulkItemResponse.fromXContent(parser, itemId);
        assertNull(parser.nextToken());
    }
    assertBulkItemResponse(expectedBulkItemResponse, parsedBulkItemResponse);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) Matchers.containsString(org.hamcrest.Matchers.containsString) ElasticsearchException(org.elasticsearch.ElasticsearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) XContentType(org.elasticsearch.common.xcontent.XContentType) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 9 with Failure

use of org.elasticsearch.action.bulk.BulkItemResponse.Failure in project elasticsearch by elastic.

the class BulkItemResponseTests method testFailureToString.

public void testFailureToString() {
    Failure failure = new Failure("index", "type", "id", new RuntimeException("test"));
    String toString = failure.toString();
    assertThat(toString, containsString("\"type\":\"runtime_exception\""));
    assertThat(toString, containsString("\"reason\":\"test\""));
    assertThat(toString, containsString("\"status\":500"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure)

Example 10 with Failure

use of org.elasticsearch.action.bulk.BulkItemResponse.Failure in project fess by codelibs.

the class FessEsClient method addAll.

public void addAll(final String index, final String type, final List<Map<String, Object>> docList) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    for (final Map<String, Object> doc : docList) {
        final Object id = doc.remove(fessConfig.getIndexFieldId());
        bulkRequestBuilder.add(client.prepareIndex(index, type, id.toString()).setSource(new DocMap(doc)));
    }
    final BulkResponse response = bulkRequestBuilder.execute().actionGet(ComponentUtil.getFessConfig().getIndexBulkTimeout());
    if (response.hasFailures()) {
        if (logger.isDebugEnabled()) {
            @SuppressWarnings("rawtypes") final List<DocWriteRequest> requests = bulkRequestBuilder.request().requests();
            final BulkItemResponse[] items = response.getItems();
            if (requests.size() == items.length) {
                for (int i = 0; i < requests.size(); i++) {
                    final BulkItemResponse resp = items[i];
                    if (resp.isFailed() && resp.getFailure() != null) {
                        final DocWriteRequest<?> req = requests.get(i);
                        final Failure failure = resp.getFailure();
                        logger.debug("Failed Request: " + req + "\n=>" + failure.getMessage());
                    }
                }
            }
        }
        throw new FessEsClientException(response.buildFailureMessage());
    }
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) DocMap(org.codelibs.fess.util.DocMap) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure)

Aggregations

Failure (org.elasticsearch.action.bulk.BulkItemResponse.Failure)10 SearchFailure (org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)5 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)4 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)3 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)3 BulkByScrollResponse (org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse)2 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 DocMap (org.codelibs.fess.util.DocMap)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 XContentType (org.elasticsearch.common.xcontent.XContentType)1