Search in sources :

Example 1 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project elasticsearch by elastic.

the class TransportNoopBulkAction method doExecute.

@Override
protected void doExecute(BulkRequest request, ActionListener<BulkResponse> listener) {
    final int itemCount = request.requests().size();
    // simulate at least a realistic amount of data that gets serialized
    BulkItemResponse[] bulkItemResponses = new BulkItemResponse[itemCount];
    for (int idx = 0; idx < itemCount; idx++) {
        bulkItemResponses[idx] = ITEM_RESPONSE;
    }
    listener.onResponse(new BulkResponse(bulkItemResponses, 0));
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 2 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse 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 3 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse 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 4 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project elasticsearch by elastic.

the class SimpleVersioningIT method testVersioningWithBulk.

public void testVersioningWithBulk() {
    createIndex("test");
    ensureGreen();
    BulkResponse bulkResponse = client().prepareBulk().add(client().prepareIndex("test", "type", "1").setSource("field1", "value1_1")).execute().actionGet();
    assertThat(bulkResponse.hasFailures(), equalTo(false));
    assertThat(bulkResponse.getItems().length, equalTo(1));
    IndexResponse indexResponse = bulkResponse.getItems()[0].getResponse();
    assertThat(indexResponse.getVersion(), equalTo(1L));
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 5 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project elasticsearch by elastic.

the class DynamicMappingIT method testConflictingDynamicMappingsBulk.

public void testConflictingDynamicMappingsBulk() {
    // we don't use indexRandom because the order of requests is important here
    createIndex("index");
    client().prepareIndex("index", "type", "1").setSource("foo", 3).get();
    BulkResponse bulkResponse = client().prepareBulk().add(client().prepareIndex("index", "type", "1").setSource("foo", 3)).get();
    assertFalse(bulkResponse.hasFailures());
    bulkResponse = client().prepareBulk().add(client().prepareIndex("index", "type", "2").setSource("foo", "bar")).get();
    assertTrue(bulkResponse.hasFailures());
}
Also used : BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Aggregations

BulkResponse (org.elasticsearch.action.bulk.BulkResponse)108 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)59 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)40 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)26 IOException (java.io.IOException)20 IndexRequest (org.elasticsearch.action.index.IndexRequest)19 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Map (java.util.Map)11 IndexResponse (org.elasticsearch.action.index.IndexResponse)10 Test (org.junit.Test)10 SearchResponse (org.elasticsearch.action.search.SearchResponse)9 SearchHit (org.elasticsearch.search.SearchHit)9 ElasticsearchException (org.elasticsearch.ElasticsearchException)8 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)8 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)8 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)8 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)7