Search in sources :

Example 6 with UpdateRequest

use of org.elasticsearch.action.update.UpdateRequest in project elasticsearch by elastic.

the class IndicesRequestIT method testUpdate.

public void testUpdate() {
    //update action goes to the primary, index op gets executed locally, then replicated
    String[] updateShardActions = new String[] { UpdateAction.NAME + "[s]", BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]" };
    interceptTransportActions(updateShardActions);
    String indexOrAlias = randomIndexOrAlias();
    client().prepareIndex(indexOrAlias, "type", "id").setSource("field", "value").get();
    UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
    UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet();
    assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
    clearInterceptedActions();
    assertSameIndices(updateRequest, updateShardActions);
}
Also used : UpdateResponse(org.elasticsearch.action.update.UpdateResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest)

Example 7 with UpdateRequest

use of org.elasticsearch.action.update.UpdateRequest in project elasticsearch by elastic.

the class RetryTests method createBulkRequest.

private BulkRequest createBulkRequest() {
    BulkRequest request = new BulkRequest();
    request.add(new UpdateRequest("shop", "products", "1"));
    request.add(new UpdateRequest("shop", "products", "2"));
    request.add(new UpdateRequest("shop", "products", "3"));
    request.add(new UpdateRequest("shop", "products", "4"));
    request.add(new UpdateRequest("shop", "products", "5"));
    return request;
}
Also used : UpdateRequest(org.elasticsearch.action.update.UpdateRequest)

Example 8 with UpdateRequest

use of org.elasticsearch.action.update.UpdateRequest in project elasticsearch by elastic.

the class TransportShardBulkActionTests method testShouldExecuteReplicaItem.

public void testShouldExecuteReplicaItem() throws Exception {
    // Successful index request should be replicated
    DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar");
    DocWriteResponse response = new IndexResponse(shardId, "type", "id", 1, 1, randomBoolean());
    BulkItemRequest request = new BulkItemRequest(0, writeRequest);
    request.setPrimaryResponse(new BulkItemResponse(0, DocWriteRequest.OpType.INDEX, response));
    assertTrue(TransportShardBulkAction.shouldExecuteReplicaItem(request, 0));
    // Failed index requests should not be replicated (for now!)
    writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar");
    response = new IndexResponse(shardId, "type", "id", 1, 1, randomBoolean());
    request = new BulkItemRequest(0, writeRequest);
    request.setPrimaryResponse(new BulkItemResponse(0, DocWriteRequest.OpType.INDEX, new BulkItemResponse.Failure("test", "type", "id", new IllegalArgumentException("i died"))));
    assertFalse(TransportShardBulkAction.shouldExecuteReplicaItem(request, 0));
    // NOOP requests should not be replicated
    writeRequest = new UpdateRequest("index", "type", "id");
    response = new UpdateResponse(shardId, "type", "id", 1, DocWriteResponse.Result.NOOP);
    request = new BulkItemRequest(0, writeRequest);
    request.setPrimaryResponse(new BulkItemResponse(0, DocWriteRequest.OpType.UPDATE, response));
    assertFalse(TransportShardBulkAction.shouldExecuteReplicaItem(request, 0));
}
Also used : UpdateResponse(org.elasticsearch.action.update.UpdateResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 9 with UpdateRequest

use of org.elasticsearch.action.update.UpdateRequest in project elasticsearch by elastic.

the class BulkRequestTests method testBulkNoSource.

// issue 15120
public void testBulkNoSource() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(new UpdateRequest("index", "type", "id"));
    bulkRequest.add(new IndexRequest("index", "type", "id"));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains("script or doc is missing", "source is missing", "content type is missing"));
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 10 with UpdateRequest

use of org.elasticsearch.action.update.UpdateRequest in project elasticsearch by elastic.

the class BulkRequestTests method testBulkAddIterable.

public void testBulkAddIterable() {
    BulkRequest bulkRequest = Requests.bulkRequest();
    List<DocWriteRequest> requests = new ArrayList<>();
    requests.add(new IndexRequest("test", "test", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
    requests.add(new UpdateRequest("test", "test", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"));
    requests.add(new DeleteRequest("test", "test", "id"));
    bulkRequest.add(requests);
    assertThat(bulkRequest.requests().size(), equalTo(3));
    assertThat(bulkRequest.requests().get(0), instanceOf(IndexRequest.class));
    assertThat(bulkRequest.requests().get(1), instanceOf(UpdateRequest.class));
    assertThat(bulkRequest.requests().get(2), instanceOf(DeleteRequest.class));
}
Also used : UpdateRequest(org.elasticsearch.action.update.UpdateRequest) ArrayList(java.util.ArrayList) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Aggregations

UpdateRequest (org.elasticsearch.action.update.UpdateRequest)56 IndexRequest (org.elasticsearch.action.index.IndexRequest)32 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)25 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)14 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)11 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)8 GetRequest (org.elasticsearch.action.get.GetRequest)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Script (org.elasticsearch.script.Script)6 HashMap (java.util.HashMap)5 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)5 WriteRequest (org.elasticsearch.action.support.WriteRequest)5 BytesReference (org.elasticsearch.common.bytes.BytesReference)5 XContentType (org.elasticsearch.common.xcontent.XContentType)5 VersionType (org.elasticsearch.index.VersionType)5 HttpEntity (org.apache.http.HttpEntity)4 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 TimeValue (org.elasticsearch.common.unit.TimeValue)4