controller.registerHandler(DELETE, "/{index}/{type}/_query", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
deleteByQueryRequest.listenerThreaded(false);
if (request.hasContent()) {
deleteByQueryRequest.source(request.content(), request.contentUnsafe());
} else {
String source = request.param("source");
if (source != null) {
deleteByQueryRequest.source(source);
} else {
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
if (querySourceBuilder != null) {
deleteByQueryRequest.source(querySourceBuilder);
}
}
}
deleteByQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
deleteByQueryRequest.timeout(request.paramAsTime("timeout", ShardDeleteByQueryRequest.DEFAULT_TIMEOUT));
deleteByQueryRequest.routing(request.param("routing"));
String replicationType = request.param("replication");
if (replicationType != null) {
deleteByQueryRequest.replicationType(ReplicationType.fromString(replicationType));
}
String consistencyLevel = request.param("consistency");
if (consistencyLevel != null) {
deleteByQueryRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
}
deleteByQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteByQueryRequest.indicesOptions()));
client.deleteByQuery(deleteByQueryRequest, new RestBuilderListener<DeleteByQueryResponse>(channel) {
@Override
public RestResponse buildResponse(DeleteByQueryResponse result, XContentBuilder builder) throws Exception {
RestStatus restStatus = result.status();
builder.startObject();