deleteByQueryRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
}
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
return;
}
client.deleteByQuery(deleteByQueryRequest, new ActionListener<DeleteByQueryResponse>() {
@Override public void onResponse(DeleteByQueryResponse result) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject().field("ok", true);
builder.startObject("_indices");
for (IndexDeleteByQueryResponse indexDeleteByQueryResponse : result.indices().values()) {
builder.startObject(indexDeleteByQueryResponse.index());
builder.startObject("_shards");
builder.field("total", indexDeleteByQueryResponse.totalShards());
builder.field("successful", indexDeleteByQueryResponse.successfulShards());
builder.field("failed", indexDeleteByQueryResponse.failedShards());
builder.endObject();
builder.endObject();
}
builder.endObject();
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
} catch (Exception e) {
onFailure(e);
}
}