Search in sources :

Example 1 with PutStoredScriptRequest

use of org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest in project elasticsearch by elastic.

the class RestPutStoredScriptAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String id = request.param("id");
    String lang = request.param("lang");
    // name ordering issues in the handlers' paths.
    if (id == null) {
        id = lang;
        lang = null;
    }
    BytesReference content = request.content();
    if (lang != null) {
        deprecationLogger.deprecated("specifying lang [" + lang + "] as part of the url path is deprecated, use request content instead");
    }
    PutStoredScriptRequest putRequest = new PutStoredScriptRequest(id, lang, content, request.getXContentType());
    return channel -> client.admin().cluster().putStoredScript(putRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) PUT(org.elasticsearch.rest.RestRequest.Method.PUT) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)

Example 2 with PutStoredScriptRequest

use of org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest in project elasticsearch by elastic.

the class RestPutSearchTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String id = request.param("id");
    BytesReference content = request.content();
    PutStoredScriptRequest put = new PutStoredScriptRequest(id, Script.DEFAULT_TEMPLATE_LANG, content, request.getXContentType());
    return channel -> client.admin().cluster().putStoredScript(put, new AcknowledgedRestListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Script(org.elasticsearch.script.Script) POST(org.elasticsearch.rest.RestRequest.Method.POST) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) PUT(org.elasticsearch.rest.RestRequest.Method.PUT) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)

Aggregations

IOException (java.io.IOException)2 PutStoredScriptRequest (org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 Settings (org.elasticsearch.common.settings.Settings)2 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)2 RestController (org.elasticsearch.rest.RestController)2 RestRequest (org.elasticsearch.rest.RestRequest)2 POST (org.elasticsearch.rest.RestRequest.Method.POST)2 PUT (org.elasticsearch.rest.RestRequest.Method.PUT)2 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)2 Script (org.elasticsearch.script.Script)1