Search in sources :

Example 16 with RestToXContentListener

use of org.elasticsearch.rest.action.RestToXContentListener in project elasticsearch by elastic.

the class RestRenderSearchTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    // Creates the render template request
    SearchTemplateRequest renderRequest;
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        renderRequest = RestSearchTemplateAction.parse(parser);
    }
    renderRequest.setSimulate(true);
    String id = request.param("id");
    if (id != null) {
        renderRequest.setScriptType(ScriptType.STORED);
        renderRequest.setScript(id);
    }
    return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
}
Also used : XContentParser(org.elasticsearch.common.xcontent.XContentParser) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) ScriptType(org.elasticsearch.script.ScriptType) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

IOException (java.io.IOException)16 NodeClient (org.elasticsearch.client.node.NodeClient)16 Settings (org.elasticsearch.common.settings.Settings)16 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)16 RestController (org.elasticsearch.rest.RestController)16 RestRequest (org.elasticsearch.rest.RestRequest)16 RestToXContentListener (org.elasticsearch.rest.action.RestToXContentListener)16 GET (org.elasticsearch.rest.RestRequest.Method.GET)10 Strings (org.elasticsearch.common.Strings)8 POST (org.elasticsearch.rest.RestRequest.Method.POST)8 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 Set (java.util.Set)2 TermVectorsRequest (org.elasticsearch.action.termvectors.TermVectorsRequest)2 VersionType (org.elasticsearch.index.VersionType)2 HEAD (org.elasticsearch.rest.RestRequest.Method.HEAD)2 RestStatus (org.elasticsearch.rest.RestStatus)2 NOT_FOUND (org.elasticsearch.rest.RestStatus.NOT_FOUND)2 OK (org.elasticsearch.rest.RestStatus.OK)2 HashSet (java.util.HashSet)1 GetTaskRequest (org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskRequest)1