Search in sources :

Example 41 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project tutorials by eugenp.

the class ElasticSearchManualTest method givenDocumentId_whenJavaObject_thenDeleteDocument.

@Test
public void givenDocumentId_whenJavaObject_thenDeleteDocument() {
    String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}";
    IndexResponse response = client.prepareIndex("people", "Doe").setSource(jsonObject).get();
    String id = response.getId();
    DeleteResponse deleteResponse = client.prepareDelete("people", "Doe", id).get();
    assertTrue(deleteResponse.isFound());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) Test(org.junit.Test)

Example 42 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project core-ng-project by neowu.

the class ElasticSearchTypeImpl method delete.

@Override
public boolean delete(DeleteRequest request) {
    StopWatch watch = new StopWatch();
    String index = request.index == null ? this.index : request.index;
    boolean deleted = false;
    try {
        DeleteResponse response = client().prepareDelete(index, type, request.id).get();
        deleted = response.getResult() == DocWriteResponse.Result.DELETED;
        return deleted;
    } catch (ElasticsearchException e) {
        // due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
        throw new SearchException(e);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("elasticsearch", elapsedTime, 0, deleted ? 1 : 0);
        logger.debug("delete, index={}, type={}, id={}, elapsedTime={}", index, type, request.id, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) SearchException(core.framework.search.SearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) StopWatch(core.framework.util.StopWatch)

Aggregations

DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)42 Test (org.junit.Test)14 IndexResponse (org.elasticsearch.action.index.IndexResponse)13 GetResponse (org.elasticsearch.action.get.GetResponse)11 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)8 HashMap (java.util.HashMap)7 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)7 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)3 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)3 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2