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.
This commit is contained in:
Ryan Ernst 2017-07-14 23:12:05 -07:00 committed by GitHub
parent 2c38e93e96
commit 072402463b
11 changed files with 47 additions and 355 deletions

View File

@ -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',
]

View File

@ -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.
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}}"
}
}
}
}
}
--------------------------------------------------

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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<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.getSource());
}
builder.endObject();
return new BytesRestResponse(found ? RestStatus.OK : RestStatus.NOT_FOUND, builder);
}
});
}
}

View File

@ -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));
}
}

View File

@ -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":

View File

@ -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:

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}
}