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());
}
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);
}
}
Aggregations