controller.registerHandler(GET, "/{index}/{type}/_count", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index")));
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
countRequest.listenerThreaded(false);
if (request.hasContent()) {
countRequest.source(request.content(), request.contentUnsafe());
} else {
String source = request.param("source");
if (source != null) {
countRequest.source(source);
} else {
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
if (querySourceBuilder != null) {
countRequest.source(querySourceBuilder);
}
}
}
countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
countRequest.preference(request.param("preference"));
final int terminateAfter = request.paramAsInt("terminate_after", DEFAULT_TERMINATE_AFTER);
if (terminateAfter < 0) {
throw new ElasticsearchIllegalArgumentException("terminateAfter must be > 0");
} else if (terminateAfter > 0) {
countRequest.terminateAfter(terminateAfter);
}
client.count(countRequest, new RestBuilderListener<CountResponse>(channel) {
@Override
public RestResponse buildResponse(CountResponse response, XContentBuilder builder) throws Exception {
builder.startObject();