controller.registerHandler(GET, "/{index}/_suggest", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
SuggestRequest suggestRequest = new SuggestRequest(Strings.splitStringByCommaToArray(request.param("index")));
suggestRequest.indicesOptions(IndicesOptions.fromRequest(request, suggestRequest.indicesOptions()));
suggestRequest.listenerThreaded(false);
if (request.hasContent()) {
suggestRequest.suggest(request.content(), request.contentUnsafe());
} else {
String source = request.param("source");
if (source != null) {
suggestRequest.suggest(source);
} else {
throw new ElasticsearchIllegalArgumentException("no content or source provided to execute suggestion");
}
}
suggestRequest.routing(request.param("routing"));
suggestRequest.preference(request.param("preference"));
client.suggest(suggestRequest, new RestBuilderListener<SuggestResponse>(channel) {
@Override
public RestResponse buildResponse(SuggestResponse response, XContentBuilder builder) throws Exception {
builder.startObject();