Search in sources :

Example 1 with Failure

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

the class AbstractAsyncBulkByScrollAction method onBulkResponse.

/**
     * Processes bulk responses, accounting for failures.
     */
void onBulkResponse(TimeValue thisBatchStartTime, BulkResponse response) {
    try {
        List<Failure> failures = new ArrayList<Failure>();
        Set<String> destinationIndicesThisBatch = new HashSet<>();
        for (BulkItemResponse item : response) {
            if (item.isFailed()) {
                recordFailure(item.getFailure(), failures);
                continue;
            }
            switch(item.getOpType()) {
                case CREATE:
                case INDEX:
                    if (item.getResponse().getResult() == DocWriteResponse.Result.CREATED) {
                        task.countCreated();
                    } else {
                        task.countUpdated();
                    }
                    break;
                case UPDATE:
                    task.countUpdated();
                    break;
                case DELETE:
                    task.countDeleted();
                    break;
            }
            // Track the indexes we've seen so we can refresh them if requested
            destinationIndicesThisBatch.add(item.getIndex());
        }
        if (task.isCancelled()) {
            finishHim(null);
            return;
        }
        addDestinationIndices(destinationIndicesThisBatch);
        if (false == failures.isEmpty()) {
            refreshAndFinish(unmodifiableList(failures), emptyList(), false);
            return;
        }
        if (mainRequest.getSize() != SIZE_ALL_MATCHES && task.getSuccessfullyProcessed() >= mainRequest.getSize()) {
            // We've processed all the requested docs.
            refreshAndFinish(emptyList(), emptyList(), false);
            return;
        }
        startNextScroll(thisBatchStartTime, response.getItems().length);
    } catch (Exception t) {
        finishHim(t);
    }
}
Also used : ArrayList(java.util.ArrayList) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) HashSet(java.util.HashSet)

Example 2 with Failure

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

the class BulkByScrollResponse method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.field("took", took.millis());
    builder.field("timed_out", timedOut);
    status.innerXContent(builder, params);
    builder.startArray("failures");
    for (Failure failure : bulkFailures) {
        builder.startObject();
        failure.toXContent(builder, params);
        builder.endObject();
    }
    for (SearchFailure failure : searchFailures) {
        failure.toXContent(builder, params);
    }
    builder.endArray();
    return builder;
}
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 3 with Failure

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

the class AsyncBulkByScrollActionTests method testBulkResponseSetsLotsOfStatus.

public void testBulkResponseSetsLotsOfStatus() {
    testRequest.setAbortOnVersionConflict(false);
    int maxBatches = randomIntBetween(0, 100);
    long versionConflicts = 0;
    long created = 0;
    long updated = 0;
    long deleted = 0;
    for (int batches = 0; batches < maxBatches; batches++) {
        BulkItemResponse[] responses = new BulkItemResponse[randomIntBetween(0, 100)];
        for (int i = 0; i < responses.length; i++) {
            ShardId shardId = new ShardId(new Index("name", "uid"), 0);
            if (rarely()) {
                versionConflicts++;
                responses[i] = new BulkItemResponse(i, randomFrom(DocWriteRequest.OpType.values()), new Failure(shardId.getIndexName(), "type", "id" + i, new VersionConflictEngineException(shardId, "type", "id", "test")));
                continue;
            }
            boolean createdResponse;
            DocWriteRequest.OpType opType;
            switch(randomIntBetween(0, 2)) {
                case 0:
                    createdResponse = true;
                    opType = DocWriteRequest.OpType.CREATE;
                    created++;
                    break;
                case 1:
                    createdResponse = false;
                    opType = randomFrom(DocWriteRequest.OpType.INDEX, DocWriteRequest.OpType.UPDATE);
                    updated++;
                    break;
                case 2:
                    createdResponse = false;
                    opType = DocWriteRequest.OpType.DELETE;
                    deleted++;
                    break;
                default:
                    throw new RuntimeException("Bad scenario");
            }
            responses[i] = new BulkItemResponse(i, opType, new IndexResponse(shardId, "type", "id" + i, randomInt(20), randomInt(), createdResponse));
        }
        new DummyAsyncBulkByScrollAction().onBulkResponse(timeValueNanos(System.nanoTime()), new BulkResponse(responses, 0));
        assertEquals(versionConflicts, testTask.getStatus().getVersionConflicts());
        assertEquals(updated, testTask.getStatus().getUpdated());
        assertEquals(created, testTask.getStatus().getCreated());
        assertEquals(deleted, testTask.getStatus().getDeleted());
        assertEquals(versionConflicts, testTask.getStatus().getVersionConflicts());
    }
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) Index(org.elasticsearch.index.Index) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ShardId(org.elasticsearch.index.shard.ShardId) VersionConflictEngineException(org.elasticsearch.index.engine.VersionConflictEngineException) IndexResponse(org.elasticsearch.action.index.IndexResponse) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)

Example 4 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 5 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)

Aggregations

Failure (org.elasticsearch.action.bulk.BulkItemResponse.Failure)11 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 IOException (java.io.IOException)2 BulkByScrollResponse (org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse)2 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 EsQueryBuilder (com.b2international.index.es.query.EsQueryBuilder)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