client.search(searchRequest, new RestStatusToXContentListener<SearchResponse>(channel));
}
public static SearchRequest parseSearchRequest(RestRequest request) {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
SearchRequest searchRequest = new SearchRequest(indices);
// get the content, and put it in the body
// add content/source as template if template flag is set
boolean isTemplateRequest = request.path().endsWith("/template");
if (request.hasContent()) {
if (isTemplateRequest) {
searchRequest.templateSource(request.content(), request.contentUnsafe());
} else {
searchRequest.source(request.content(), request.contentUnsafe());
}
} else {
String source = request.param("source");
if (source != null) {
if (isTemplateRequest) {
searchRequest.templateSource(source);
} else {
searchRequest.source(source);
}
}
}
searchRequest.extraSource(parseSearchSource(request));
searchRequest.searchType(request.param("search_type"));
searchRequest.queryCache(request.paramAsBoolean("query_cache", null));
String scroll = request.param("scroll");
if (scroll != null) {
searchRequest.scroll(new Scroll(parseTimeValue(scroll, null)));
}
searchRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
searchRequest.routing(request.param("routing"));
searchRequest.preference(request.param("preference"));
searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
return searchRequest;
}