use of org.elasticsearch.script.StoredScriptSource in project elasticsearch by elastic.
the class RestGetSearchTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, NodeClient client) throws IOException {
String id = request.param("id");
GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id, Script.DEFAULT_TEMPLATE_LANG);
return channel -> client.admin().cluster().getStoredScript(getRequest, new RestBuilderListener<GetStoredScriptResponse>(channel) {
@Override
public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
builder.field(_ID_PARSE_FIELD.getPreferredName(), id);
builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), Script.DEFAULT_TEMPLATE_LANG);
StoredScriptSource source = response.getSource();
boolean found = source != null;
builder.field(FOUND_PARSE_FIELD.getPreferredName(), found);
if (found) {
builder.field(StoredScriptSource.TEMPLATE_PARSE_FIELD.getPreferredName(), source.getCode());
}
builder.endObject();
return new BytesRestResponse(found ? RestStatus.OK : RestStatus.NOT_FOUND, builder);
}
});
}
use of org.elasticsearch.script.StoredScriptSource in project elasticsearch by elastic.
the class RestGetStoredScriptAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, NodeClient client) throws IOException {
String id;
String lang;
// name ordering issues in the handlers' paths.
if (request.param("id") == null) {
id = request.param("lang");
;
lang = null;
} else {
id = request.param("id");
lang = request.param("lang");
}
if (lang != null) {
deprecationLogger.deprecated("specifying lang [" + lang + "] as part of the url path is deprecated");
}
GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id, lang);
return channel -> client.admin().cluster().getStoredScript(getRequest, new RestBuilderListener<GetStoredScriptResponse>(channel) {
@Override
public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
builder.field(_ID_PARSE_FIELD.getPreferredName(), id);
if (lang != null) {
builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), lang);
}
StoredScriptSource source = response.getSource();
boolean found = source != null;
builder.field(FOUND_PARSE_FIELD.getPreferredName(), found);
if (found) {
if (lang == null) {
builder.startObject(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName());
builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), source.getLang());
builder.field(StoredScriptSource.CODE_PARSE_FIELD.getPreferredName(), source.getCode());
if (source.getOptions().isEmpty() == false) {
builder.field(StoredScriptSource.OPTIONS_PARSE_FIELD.getPreferredName(), source.getOptions());
}
builder.endObject();
} else {
builder.field(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName(), source.getCode());
}
}
builder.endObject();
return new BytesRestResponse(found ? RestStatus.OK : RestStatus.NOT_FOUND, builder);
}
});
}
Aggregations