controller.registerHandler(POST, "/{index}/{type}/_count", this);
controller.registerHandler(GET, "/{index}/{type}/_count", this);
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
CountRequest countRequest = new CountRequest(RestActions.splitIndices(request.param("index")));
// we just send back a response, no need to fork a listener
countRequest.listenerThreaded(false);
try {
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD);
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {
// since we don't spawn, don't allow no_threads, but change it to a single thread
operationThreading = BroadcastOperationThreading.SINGLE_THREAD;
}
countRequest.operationThreading(operationThreading);
if (request.hasContent()) {
countRequest.query(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), true);
} else {
String source = request.param("source");
if (source != null) {
countRequest.query(source);
} else {
countRequest.query(RestActions.parseQuerySource(request));
}
}
countRequest.queryHint(request.param("query_hint"));
countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
countRequest.types(splitTypes(request.param("type")));
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {