From 072402463bb75b298a9ac3814440739011fc8d8f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Fri, 14 Jul 2017 23:12:05 -0700 Subject: [PATCH] Scripting: Remove search template actions (#25717) The dedicated search template put/get/delete actions are deprecated in 5.6. This commit removes them from 6.0. --- docs/build.gradle | 1 + .../migration/migrate_6_0/scripting.asciidoc | 40 +++++++- .../script/mustache/MustachePlugin.java | 3 - .../RestDeleteSearchTemplateAction.java | 59 ------------ .../mustache/RestGetSearchTemplateAction.java | 91 ------------------- .../mustache/RestPutSearchTemplateAction.java | 66 -------------- .../test/lang_mustache/10_basic.yml | 63 ------------- .../test/old_cluster/10_basic.yml | 16 ++-- .../rest-api-spec/api/delete_template.json | 20 ---- .../rest-api-spec/api/get_template.json | 20 ---- .../rest-api-spec/api/put_template.json | 23 ----- 11 files changed, 47 insertions(+), 355 deletions(-) delete mode 100644 modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestDeleteSearchTemplateAction.java delete mode 100644 modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java delete mode 100644 modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestPutSearchTemplateAction.java delete mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/delete_template.json delete mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/get_template.json delete mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/put_template.json diff --git a/docs/build.gradle b/docs/build.gradle index ee45e4d84ae..e61ad146c5b 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -52,6 +52,7 @@ buildRestTests.expectedUnconvertedCandidates = [ 'reference/indices/segments.asciidoc', 'reference/indices/shard-stores.asciidoc', 'reference/mapping/removal_of_types.asciidoc', + 'reference/migration/migrate_6_0/scripting.asciidoc', 'reference/search/profile.asciidoc', ] diff --git a/docs/reference/migration/migrate_6_0/scripting.asciidoc b/docs/reference/migration/migrate_6_0/scripting.asciidoc index b5762666dd1..c964f290bc8 100644 --- a/docs/reference/migration/migrate_6_0/scripting.asciidoc +++ b/docs/reference/migration/migrate_6_0/scripting.asciidoc @@ -33,4 +33,42 @@ The `lang` variable can no longer be specified as part of a request that uses a script otherwise an error will occur. Note that a request using a stored script is different from a request that puts a stored script. The language of the script has already been stored as part of the cluster state and an `id` is sufficient to access -all of the information necessary to execute a stored script. \ No newline at end of file +all of the information necessary to execute a stored script. + +==== Stored search template apis removed + +The PUT, GET and DELETE `_search/template` apis have been removed. Store search templates with the stored scripts apis instead. + +For example, previously one might have stored a search template with the following: + +[source,js] +-------------------------------------------------- +PUT /_search/template/my_template +{ + "query": { + "match": { + "f1": "{{f1}}" + } + } +} +-------------------------------------------------- + +And instead one would now use the following: + +[source,js] +-------------------------------------------------- +PUT /_scripts/my_template +{ + "script": { + "lang": "mustache", + "source": { + "query": { + "match": { + "f1": "{{f1}}" + } + } + } + } +} +-------------------------------------------------- + diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java index c05a88e9351..ee0d50ad2cc 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java @@ -61,9 +61,6 @@ public class MustachePlugin extends Plugin implements ScriptPlugin, ActionPlugin return Arrays.asList( new RestSearchTemplateAction(settings, restController), new RestMultiSearchTemplateAction(settings, restController), - new RestGetSearchTemplateAction(settings, restController), - new RestPutSearchTemplateAction(settings, restController), - new RestDeleteSearchTemplateAction(settings, restController), new RestRenderSearchTemplateAction(settings, restController)); } } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestDeleteSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestDeleteSearchTemplateAction.java deleted file mode 100644 index 2db57c65631..00000000000 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestDeleteSearchTemplateAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.script.mustache; - -import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.AcknowledgedRestListener; -import org.elasticsearch.script.Script; - -import java.io.IOException; - -import static org.elasticsearch.rest.RestRequest.Method.DELETE; - -public class RestDeleteSearchTemplateAction extends BaseRestHandler { - private static final DeprecationLogger DEPRECATION_LOGGER = - new DeprecationLogger(Loggers.getLogger(RestDeleteSearchTemplateAction.class)); - - public RestDeleteSearchTemplateAction(Settings settings, RestController controller) { - super(settings); - - controller.registerAsDeprecatedHandler(DELETE, "/_search/template/{id}", this, - "The stored search template API is deprecated. Use stored scripts instead.", DEPRECATION_LOGGER); - } - - @Override - public String getName() { - return "delete_search_template_action"; - } - - @Override - public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - String id = request.param("id"); - - DeleteStoredScriptRequest deleteStoredScriptRequest = new DeleteStoredScriptRequest(id, Script.DEFAULT_TEMPLATE_LANG); - return channel -> client.admin().cluster().deleteStoredScript(deleteStoredScriptRequest, new AcknowledgedRestListener<>(channel)); - } -} diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java deleted file mode 100644 index 3a69a9e25f4..00000000000 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.script.mustache; - -import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; -import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse; -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.RestBuilderListener; -import org.elasticsearch.script.Script; -import org.elasticsearch.script.StoredScriptSource; - -import java.io.IOException; - -import static org.elasticsearch.rest.RestRequest.Method.GET; - -public class RestGetSearchTemplateAction extends BaseRestHandler { - private static final DeprecationLogger DEPRECATION_LOGGER = - new DeprecationLogger(Loggers.getLogger(RestGetSearchTemplateAction.class)); - - public static final ParseField _ID_PARSE_FIELD = new ParseField("_id"); - - public static final ParseField FOUND_PARSE_FIELD = new ParseField("found"); - - public RestGetSearchTemplateAction(Settings settings, RestController controller) { - super(settings); - - controller.registerAsDeprecatedHandler(GET, "/_search/template/{id}", this, - "The stored search template API is deprecated. Use stored scripts instead.", DEPRECATION_LOGGER); - } - - @Override - public String getName() { - return "get_search_template_action"; - } - - @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(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.getSource()); - } - - builder.endObject(); - - return new BytesRestResponse(found ? RestStatus.OK : RestStatus.NOT_FOUND, builder); - } - }); - } -} diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestPutSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestPutSearchTemplateAction.java deleted file mode 100644 index e6e6e139289..00000000000 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestPutSearchTemplateAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.script.mustache; - -import java.io.IOException; - -import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest; -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.AcknowledgedRestListener; -import org.elasticsearch.script.Script; -import org.elasticsearch.script.TemplateScript; - -import static org.elasticsearch.rest.RestRequest.Method.POST; -import static org.elasticsearch.rest.RestRequest.Method.PUT; - -public class RestPutSearchTemplateAction extends BaseRestHandler { - - private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(RestPutSearchTemplateAction.class)); - - public RestPutSearchTemplateAction(Settings settings, RestController controller) { - super(settings); - - controller.registerAsDeprecatedHandler(POST, "/_search/template/{id}", this, - "The stored search template API is deprecated. Use stored scripts instead.", DEPRECATION_LOGGER); - controller.registerAsDeprecatedHandler(PUT, "/_search/template/{id}", this, - "The stored search template API is deprecated. Use stored scripts instead.", DEPRECATION_LOGGER); - } - - @Override - public String getName() { - return "put_search_template_action"; - } - - @Override - public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - String id = request.param("id"); - BytesReference content = request.requiredContent(); - - PutStoredScriptRequest put = new PutStoredScriptRequest(id, Script.DEFAULT_TEMPLATE_LANG, TemplateScript.CONTEXT.name, - content, request.getXContentType()); - return channel -> client.admin().cluster().putStoredScript(put, new AcknowledgedRestListener<>(channel)); - } -} diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/10_basic.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/10_basic.yml index 4e1ce5b1b4e..25a7845a4b5 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/10_basic.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/10_basic.yml @@ -12,69 +12,6 @@ - match: { nodes.$master.modules.0.name: lang-mustache } ---- -"Stored template": - - skip: - features: "warnings" - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - put_template: - id: "1" - body: { "template": { "query": { "match_all": {}}, "size": "{{my_size}}" } } - - match: { acknowledged: true } - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - get_template: - id: 1 - - match: { found: true } - - match: { lang: mustache } - - match: { _id: "1" } - - match: { template: /.*query\S\S\S\Smatch_all.*/ } - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - catch: missing - get_template: - id: 2 - - match: { found: false } - - match: { lang: mustache } - - match: { _id: "2" } - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - delete_template: - id: "1" - - match: { acknowledged: true } - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - catch: missing - delete_template: - id: "non_existing" - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - catch: request - put_template: - id: "1" - body: { "template": { "query": { "match{{}}_all": {}}, "size": "{{my_size}}" } } - - - do: - warnings: - - "The stored search template API is deprecated. Use stored scripts instead." - catch: /failed\sto\sparse.*/ - put_template: - id: "1" - body: { "template": { "query": { "match{{}}_all": {}}, "size": "{{my_size}}" } } - --- "missing body": diff --git a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml index f621d95e4a5..fcaf663ee0b 100644 --- a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml +++ b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml @@ -1,8 +1,5 @@ --- "Index data, search, and create things in the cluster state that we'll validate are there after the ugprade": - - skip: - features: warnings - - do: indices.create: index: test_index @@ -108,14 +105,15 @@ - match: { "acknowledged": true } - do: - warnings: - - 'The stored search template API is deprecated. Use stored scripts instead.' - put_template: + put_script: id: test_search_template body: - query: - match: - f1: "{{f1}}" + script: + lang: mustache + source: + query: + match: + f1: "{{f1}}" - match: { acknowledged: true } - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_template.json deleted file mode 100644 index e1e40bd95b6..00000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_template.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "delete_template": { - "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html", - "methods": ["DELETE"], - "url": { - "path": "/_search/template/{id}", - "paths": [ "/_search/template/{id}" ], - "parts": { - "id": { - "type" : "string", - "description" : "Template ID", - "required" : true - } - }, - "params" : { - } - }, - "body": null - } -} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/get_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/get_template.json deleted file mode 100644 index 487b81c5350..00000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/get_template.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "get_template": { - "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html", - "methods": ["GET"], - "url": { - "path": "/_search/template/{id}", - "paths": [ "/_search/template/{id}" ], - "parts": { - "id": { - "type" : "string", - "description" : "Template ID", - "required" : true - } - }, - "params" : { - } - }, - "body": null - } -} \ No newline at end of file diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/put_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/put_template.json deleted file mode 100644 index 294ed32cfff..00000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/put_template.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "put_template": { - "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html", - "methods": ["PUT", "POST"], - "url": { - "path": "/_search/template/{id}", - "paths": [ "/_search/template/{id}" ], - "parts": { - "id": { - "type" : "string", - "description" : "Template ID", - "required" : true - } - }, - "params" : { - } - }, - "body": { - "description" : "The document", - "required" : true - } - } -}