Search in sources :

Example 21 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project elasticsearch by elastic.

the class RequestTests method testDelete.

public void testDelete() throws IOException {
    String index = randomAsciiOfLengthBetween(3, 10);
    String type = randomAsciiOfLengthBetween(3, 10);
    String id = randomAsciiOfLengthBetween(3, 10);
    DeleteRequest deleteRequest = new DeleteRequest(index, type, id);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomTimeout(deleteRequest, expectedParams);
    setRandomRefreshPolicy(deleteRequest, expectedParams);
    setRandomVersion(deleteRequest, expectedParams);
    setRandomVersionType(deleteRequest, expectedParams);
    if (frequently()) {
        if (randomBoolean()) {
            String routing = randomAsciiOfLengthBetween(3, 10);
            deleteRequest.routing(routing);
            expectedParams.put("routing", routing);
        }
        if (randomBoolean()) {
            String parent = randomAsciiOfLengthBetween(3, 10);
            deleteRequest.parent(parent);
            expectedParams.put("parent", parent);
        }
    }
    Request request = Request.delete(deleteRequest);
    assertEquals("/" + index + "/" + type + "/" + id, request.endpoint);
    assertEquals(expectedParams, request.params);
    assertEquals("DELETE", request.method);
    assertNull(request.entity);
}
Also used : HashMap(java.util.HashMap) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) WriteRequest(org.elasticsearch.action.support.WriteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) BulkShardRequest(org.elasticsearch.action.bulk.BulkShardRequest) GetRequest(org.elasticsearch.action.get.GetRequest) ReplicatedWriteRequest(org.elasticsearch.action.support.replication.ReplicatedWriteRequest) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) ReplicationRequest(org.elasticsearch.action.support.replication.ReplicationRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 22 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project elasticsearch by elastic.

the class BulkRequestTests method testBulkRequestWithRefresh.

// issue 7361
public void testBulkRequestWithRefresh() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    // We force here a "id is missing" validation error
    bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    // We force here a "type is missing" validation error
    bulkRequest.add(new DeleteRequest("index", null, "id"));
    bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains("RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "id is missing", "type is missing", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead."));
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 23 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project elasticsearch by elastic.

the class BulkWithUpdatesIT method testFailedRequestsOnClosedIndex.

// issue 9821
public void testFailedRequestsOnClosedIndex() throws Exception {
    createIndex("bulkindex1");
    client().prepareIndex("bulkindex1", "index1_type", "1").setSource("text", "test").get();
    assertAcked(client().admin().indices().prepareClose("bulkindex1"));
    BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE);
    bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")).add(new UpdateRequest("bulkindex1", "index1_type", "1").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")).add(new DeleteRequest("bulkindex1", "index1_type", "1"));
    BulkResponse bulkResponse = client().bulk(bulkRequest).get();
    assertThat(bulkResponse.hasFailures(), is(true));
    BulkItemResponse[] responseItems = bulkResponse.getItems();
    assertThat(responseItems.length, is(3));
    assertThat(responseItems[0].getOpType(), is(OpType.INDEX));
    assertThat(responseItems[1].getOpType(), is(OpType.UPDATE));
    assertThat(responseItems[2].getOpType(), is(OpType.DELETE));
}
Also used : UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 24 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project elasticsearch by elastic.

the class AbstractAsyncBulkByScrollActionScriptTestCase method testSetOpTypeDelete.

public void testSetOpTypeDelete() throws Exception {
    DeleteRequest delete = applyScript((Map<String, Object> ctx) -> ctx.put("op", OpType.DELETE.toString()));
    assertThat(delete.index(), equalTo("index"));
    assertThat(delete.type(), equalTo("type"));
    assertThat(delete.id(), equalTo("1"));
}
Also used : DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 25 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project elasticsearch by elastic.

the class IndicesRequestIT method testDelete.

public void testDelete() {
    String[] deleteShardActions = new String[] { BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]" };
    interceptTransportActions(deleteShardActions);
    DeleteRequest deleteRequest = new DeleteRequest(randomIndexOrAlias(), "type", "id");
    internalCluster().coordOnlyNodeClient().delete(deleteRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(deleteRequest, deleteShardActions);
}
Also used : DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Aggregations

DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)33 IndexRequest (org.elasticsearch.action.index.IndexRequest)25 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)18 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)8 IOException (java.io.IOException)7 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)7 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)7 ArrayList (java.util.ArrayList)5 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)4 GetRequest (org.elasticsearch.action.get.GetRequest)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4 XContentType (org.elasticsearch.common.xcontent.XContentType)4 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)3 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)3 VersionConflictEngineException (org.elasticsearch.index.engine.VersionConflictEngineException)3 TitanException (com.thinkaurelius.titan.core.TitanException)2 FileNotFoundException (java.io.FileNotFoundException)2