Scripting: Deprecate stored search template apis (#25437)

This commit deprecates the PUT, GET and DELETE search template apis.
Instead, the stored script api should be used.

closes #24596
This commit is contained in:
Ryan Ernst 2017-07-12 16:07:28 -07:00 committed by GitHub
parent e2bfb35f4a
commit 70b2897bdf
10 changed files with 119 additions and 70 deletions

View File

@ -116,12 +116,15 @@ You can also create search templates:
[source,js]
------------------------------------------
POST /_search/template/my_template_1
POST /_scripts/my_template_1
{
"template": {
"query": {
"match": {
"message": "{{query_string}}"
"script": {
"lang": "mustache",
"source": {
"query": {
"match": {
"message": "{{query_string}}"
}
}
}
}
@ -132,12 +135,15 @@ POST /_search/template/my_template_1
[source,js]
------------------------------------------
POST /_search/template/my_template_2
POST /_scripts/my_template_2
{
"template": {
"query": {
"term": {
"{{field}}": "{{value}}"
"script": {
"lang": "mustache",
"source": {
"query": {
"term": {
"{{field}}": "{{value}}"
}
}
}
}

View File

@ -402,17 +402,19 @@ The previous query will be rendered as:
[[pre-registered-templates]]
===== Pre-registered template
You can register search templates by storing them in the cluster state.
There are REST APIs to manage these stored templates.
You can register search templates by using the stored scripts api.
[source,js]
------------------------------------------
POST _search/template/<templatename>
POST _scripts/<templatename>
{
"template": {
"query": {
"match": {
"title": "{{query_string}}"
"script": {
"lang": "mustache",
"source": {
"query": {
"match": {
"title": "{{query_string}}"
}
}
}
}
@ -440,7 +442,7 @@ This template can be retrieved by
[source,js]
------------------------------------------
GET _search/template/<templatename>
GET _scripts/<templatename>
------------------------------------------
// CONSOLE
// TEST[continued]
@ -450,10 +452,15 @@ which is rendered as:
[source,js]
------------------------------------------
{
"_id" : "<templatename>",
"lang" : "mustache",
"found" : true,
"template" : "{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}"
"script" : {
"lang" : "mustache",
"source" : "{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}",
"options": {
"content_type" : "application/json; charset=UTF-8"
}
},
"_id": "<templatename>",
"found": true
}
------------------------------------------
// TESTRESPONSE
@ -462,7 +469,7 @@ This template can be deleted by
[source,js]
------------------------------------------
DELETE _search/template/<templatename>
DELETE _scripts/<templatename>
------------------------------------------
// CONSOLE
// TEST[continued]

View File

@ -20,6 +20,8 @@ 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;
@ -32,11 +34,14 @@ 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.registerHandler(DELETE, "/_search/template/{id}", this);
controller.registerAsDeprecatedHandler(DELETE, "/_search/template/{id}", this,
"The stored search template API is deprecated. Use stored scripts instead.", DEPRECATION_LOGGER);
}
@Override

View File

@ -22,6 +22,8 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptReque
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;
@ -39,6 +41,8 @@ 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");
@ -47,7 +51,8 @@ public class RestGetSearchTemplateAction extends BaseRestHandler {
public RestGetSearchTemplateAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_search/template/{id}", this);
controller.registerAsDeprecatedHandler(GET, "/_search/template/{id}", this,
"The stored search template API is deprecated. Use stored scripts instead.", DEPRECATION_LOGGER);
}
@Override

View File

@ -23,6 +23,8 @@ 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;
@ -36,11 +38,15 @@ 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.registerHandler(POST, "/_search/template/{id}", this);
controller.registerHandler(PUT, "/_search/template/{id}", this);
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

View File

@ -13,15 +13,21 @@
- match: { nodes.$master.modules.0.name: lang-mustache }
---
"Indexed template":
"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 }
@ -30,6 +36,8 @@
- 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
@ -38,22 +46,30 @@
- 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"

View File

@ -2,9 +2,9 @@
"Stored Template validate tests":
- do:
put_template:
put_script:
id: "1"
body: { "template": { "query": { "match": { "text": "{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } } }
body: { "script": { "lang": "mustache", "source": { "query": { "match": { "text": "{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } } } }
- match: { acknowledged: true }
- do:
@ -54,9 +54,9 @@
"Escaped Stored Template validate tests":
- do:
put_template:
put_script:
id: "1"
body: { "template": "{ \"query\": { \"match\": { \"text\": \"{{my_value}}\" } }, \"size\": {{my_size}} }" }
body: { "script": { "lang" : "mustache", "source" : "{ \"query\": { \"match\": { \"text\": \"{{my_value}}\" } }, \"size\": {{my_size}} }" } }
- match: { acknowledged: true }
- do:
@ -122,9 +122,9 @@
indices.refresh: {}
- do:
put_template:
put_script:
id: "1"
body: { "template": { "query": { "match" : { "text": "{{my_value}}" } }, "size": "{{my_size}}" } }
body: { "script": { "lang": "mustache", "source": { "query": { "match" : { "text": "{{my_value}}" } }, "size": "{{my_size}}" } } }
- match: { acknowledged: true }
- do:

View File

@ -23,9 +23,9 @@
- match: { hits.total: 1 }
- do:
put_template:
put_script:
id: "1"
body: { "template": { "query": { "term": { "text": "{{template}}" } } } }
body: { "script": { "lang": "mustache", "source": { "query": { "term": { "text": "{{template}}" } } } } }
- match: { acknowledged: true }
- do:
@ -88,9 +88,9 @@
indices.refresh: {}
- do:
put_template:
put_script:
id: "template_1"
body: { "template": { "query": { "match": { "{{field}}": { "query" : "{{value}}", "operator" : "{{operator}}{{^operator}}or{{/operator}}" } } }, "size": "{{size}}" } }
body: { "script": { "lang": "mustache", "source": { "query": { "match": { "{{field}}": { "query" : "{{value}}", "operator" : "{{operator}}{{^operator}}or{{/operator}}" } } }, "size": "{{size}}" } } }
- match: { acknowledged: true }
- do:

View File

@ -129,9 +129,9 @@ setup:
"Basic multi-search using stored template":
- do:
put_template:
put_script:
id: stored_template_1
body: {"template": {"query": {"match": {"{{field}}": "{{value}}" }}}}
body: { "script": { "lang" : "mustache", "source": { "query": {"match": {"{{field}}": "{{value}}" }}}}}
- match: { acknowledged: true }
- do:

View File

@ -37,22 +37,24 @@ setup:
"Search template with typed_keys parameter":
- do:
put_template:
put_script:
id: template_1
body:
template:
query:
match:
bool: "{{bool_value}}"
aggs:
test_missing:
missing:
field: "{{missing_field}}"
suggest:
term_suggest:
text: "{{suggest_text}}"
term:
field: "{{suggest_field}}"
script:
lang: mustache
source:
query:
match:
bool: "{{bool_value}}"
aggs:
test_missing:
missing:
field: "{{missing_field}}"
suggest:
term_suggest:
text: "{{suggest_text}}"
term:
field: "{{suggest_field}}"
- match: { acknowledged: true }
@ -76,24 +78,26 @@ setup:
"Multisearch template with typed_keys parameter":
- do:
put_template:
put_script:
id: registered_template
body:
template:
query:
range:
integer:
gte: "{{starting_value}}"
aggs:
test_histogram:
histogram:
field: "{{histo.field}}"
interval: "{{histo.interval}}"
suggest:
phrase_suggester:
text: "{{keywords}}"
phrase:
field: name
script:
lang: mustache
source:
query:
range:
integer:
gte: "{{starting_value}}"
aggs:
test_histogram:
histogram:
field: "{{histo.field}}"
interval: "{{histo.interval}}"
suggest:
phrase_suggester:
text: "{{keywords}}"
phrase:
field: name
- match: { acknowledged: true }