mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-08 22:14:59 +00:00
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:
parent
e2bfb35f4a
commit
70b2897bdf
@ -116,9 +116,11 @@ You can also create search templates:
|
|||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
POST /_search/template/my_template_1
|
POST /_scripts/my_template_1
|
||||||
{
|
{
|
||||||
"template": {
|
"script": {
|
||||||
|
"lang": "mustache",
|
||||||
|
"source": {
|
||||||
"query": {
|
"query": {
|
||||||
"match": {
|
"match": {
|
||||||
"message": "{{query_string}}"
|
"message": "{{query_string}}"
|
||||||
@ -126,15 +128,18 @@ POST /_search/template/my_template_1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
// TEST[setup:twitter]
|
// TEST[setup:twitter]
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
POST /_search/template/my_template_2
|
POST /_scripts/my_template_2
|
||||||
{
|
{
|
||||||
"template": {
|
"script": {
|
||||||
|
"lang": "mustache",
|
||||||
|
"source": {
|
||||||
"query": {
|
"query": {
|
||||||
"term": {
|
"term": {
|
||||||
"{{field}}": "{{value}}"
|
"{{field}}": "{{value}}"
|
||||||
@ -142,6 +147,7 @@ POST /_search/template/my_template_2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
// TEST[continued]
|
// TEST[continued]
|
||||||
|
@ -402,14 +402,15 @@ The previous query will be rendered as:
|
|||||||
[[pre-registered-templates]]
|
[[pre-registered-templates]]
|
||||||
===== Pre-registered template
|
===== Pre-registered template
|
||||||
|
|
||||||
You can register search templates by storing them in the cluster state.
|
You can register search templates by using the stored scripts api.
|
||||||
There are REST APIs to manage these stored templates.
|
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
POST _search/template/<templatename>
|
POST _scripts/<templatename>
|
||||||
{
|
{
|
||||||
"template": {
|
"script": {
|
||||||
|
"lang": "mustache",
|
||||||
|
"source": {
|
||||||
"query": {
|
"query": {
|
||||||
"match": {
|
"match": {
|
||||||
"title": "{{query_string}}"
|
"title": "{{query_string}}"
|
||||||
@ -417,6 +418,7 @@ POST _search/template/<templatename>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
// TEST[continued]
|
// TEST[continued]
|
||||||
@ -440,7 +442,7 @@ This template can be retrieved by
|
|||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
GET _search/template/<templatename>
|
GET _scripts/<templatename>
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
// TEST[continued]
|
// TEST[continued]
|
||||||
@ -450,10 +452,15 @@ which is rendered as:
|
|||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
{
|
{
|
||||||
"_id" : "<templatename>",
|
"script" : {
|
||||||
"lang" : "mustache",
|
"lang" : "mustache",
|
||||||
"found" : true,
|
"source" : "{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}",
|
||||||
"template" : "{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}"
|
"options": {
|
||||||
|
"content_type" : "application/json; charset=UTF-8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"_id": "<templatename>",
|
||||||
|
"found": true
|
||||||
}
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
// TESTRESPONSE
|
// TESTRESPONSE
|
||||||
@ -462,7 +469,7 @@ This template can be deleted by
|
|||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
DELETE _search/template/<templatename>
|
DELETE _scripts/<templatename>
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
// TEST[continued]
|
// TEST[continued]
|
||||||
|
@ -20,6 +20,8 @@ package org.elasticsearch.script.mustache;
|
|||||||
|
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
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.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
@ -32,11 +34,14 @@ import java.io.IOException;
|
|||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
|
|
||||||
public class RestDeleteSearchTemplateAction extends BaseRestHandler {
|
public class RestDeleteSearchTemplateAction extends BaseRestHandler {
|
||||||
|
private static final DeprecationLogger DEPRECATION_LOGGER =
|
||||||
|
new DeprecationLogger(Loggers.getLogger(RestDeleteSearchTemplateAction.class));
|
||||||
|
|
||||||
public RestDeleteSearchTemplateAction(Settings settings, RestController controller) {
|
public RestDeleteSearchTemplateAction(Settings settings, RestController controller) {
|
||||||
super(settings);
|
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
|
@Override
|
||||||
|
@ -22,6 +22,8 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptReque
|
|||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.ParseField;
|
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.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
@ -39,6 +41,8 @@ import java.io.IOException;
|
|||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
public class RestGetSearchTemplateAction extends BaseRestHandler {
|
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 _ID_PARSE_FIELD = new ParseField("_id");
|
||||||
|
|
||||||
@ -47,7 +51,8 @@ public class RestGetSearchTemplateAction extends BaseRestHandler {
|
|||||||
public RestGetSearchTemplateAction(Settings settings, RestController controller) {
|
public RestGetSearchTemplateAction(Settings settings, RestController controller) {
|
||||||
super(settings);
|
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
|
@Override
|
||||||
|
@ -23,6 +23,8 @@ import java.io.IOException;
|
|||||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
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.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
@ -36,11 +38,15 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
|||||||
|
|
||||||
public class RestPutSearchTemplateAction extends BaseRestHandler {
|
public class RestPutSearchTemplateAction extends BaseRestHandler {
|
||||||
|
|
||||||
|
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(RestPutSearchTemplateAction.class));
|
||||||
|
|
||||||
public RestPutSearchTemplateAction(Settings settings, RestController controller) {
|
public RestPutSearchTemplateAction(Settings settings, RestController controller) {
|
||||||
super(settings);
|
super(settings);
|
||||||
|
|
||||||
controller.registerHandler(POST, "/_search/template/{id}", this);
|
controller.registerAsDeprecatedHandler(POST, "/_search/template/{id}", this,
|
||||||
controller.registerHandler(PUT, "/_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
|
@Override
|
||||||
|
@ -13,15 +13,21 @@
|
|||||||
- match: { nodes.$master.modules.0.name: lang-mustache }
|
- match: { nodes.$master.modules.0.name: lang-mustache }
|
||||||
|
|
||||||
---
|
---
|
||||||
"Indexed template":
|
"Stored template":
|
||||||
|
- skip:
|
||||||
|
features: "warnings"
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
put_template:
|
put_template:
|
||||||
id: "1"
|
id: "1"
|
||||||
body: { "template": { "query": { "match_all": {}}, "size": "{{my_size}}" } }
|
body: { "template": { "query": { "match_all": {}}, "size": "{{my_size}}" } }
|
||||||
- match: { acknowledged: true }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
get_template:
|
get_template:
|
||||||
id: 1
|
id: 1
|
||||||
- match: { found: true }
|
- match: { found: true }
|
||||||
@ -30,6 +36,8 @@
|
|||||||
- match: { template: /.*query\S\S\S\Smatch_all.*/ }
|
- match: { template: /.*query\S\S\S\Smatch_all.*/ }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
catch: missing
|
catch: missing
|
||||||
get_template:
|
get_template:
|
||||||
id: 2
|
id: 2
|
||||||
@ -38,22 +46,30 @@
|
|||||||
- match: { _id: "2" }
|
- match: { _id: "2" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
delete_template:
|
delete_template:
|
||||||
id: "1"
|
id: "1"
|
||||||
- match: { acknowledged: true }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
catch: missing
|
catch: missing
|
||||||
delete_template:
|
delete_template:
|
||||||
id: "non_existing"
|
id: "non_existing"
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
catch: request
|
catch: request
|
||||||
put_template:
|
put_template:
|
||||||
id: "1"
|
id: "1"
|
||||||
body: { "template": { "query": { "match{{}}_all": {}}, "size": "{{my_size}}" } }
|
body: { "template": { "query": { "match{{}}_all": {}}, "size": "{{my_size}}" } }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The stored search template API is deprecated. Use stored scripts instead."
|
||||||
catch: /failed\sto\sparse.*/
|
catch: /failed\sto\sparse.*/
|
||||||
put_template:
|
put_template:
|
||||||
id: "1"
|
id: "1"
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
"Stored Template validate tests":
|
"Stored Template validate tests":
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: "1"
|
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 }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
@ -54,9 +54,9 @@
|
|||||||
"Escaped Stored Template validate tests":
|
"Escaped Stored Template validate tests":
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: "1"
|
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 }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
@ -122,9 +122,9 @@
|
|||||||
indices.refresh: {}
|
indices.refresh: {}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: "1"
|
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 }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
@ -23,9 +23,9 @@
|
|||||||
- match: { hits.total: 1 }
|
- match: { hits.total: 1 }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: "1"
|
id: "1"
|
||||||
body: { "template": { "query": { "term": { "text": "{{template}}" } } } }
|
body: { "script": { "lang": "mustache", "source": { "query": { "term": { "text": "{{template}}" } } } } }
|
||||||
- match: { acknowledged: true }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
@ -88,9 +88,9 @@
|
|||||||
indices.refresh: {}
|
indices.refresh: {}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: "template_1"
|
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 }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
@ -129,9 +129,9 @@ setup:
|
|||||||
"Basic multi-search using stored template":
|
"Basic multi-search using stored template":
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: stored_template_1
|
id: stored_template_1
|
||||||
body: {"template": {"query": {"match": {"{{field}}": "{{value}}" }}}}
|
body: { "script": { "lang" : "mustache", "source": { "query": {"match": {"{{field}}": "{{value}}" }}}}}
|
||||||
- match: { acknowledged: true }
|
- match: { acknowledged: true }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
@ -37,10 +37,12 @@ setup:
|
|||||||
"Search template with typed_keys parameter":
|
"Search template with typed_keys parameter":
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: template_1
|
id: template_1
|
||||||
body:
|
body:
|
||||||
template:
|
script:
|
||||||
|
lang: mustache
|
||||||
|
source:
|
||||||
query:
|
query:
|
||||||
match:
|
match:
|
||||||
bool: "{{bool_value}}"
|
bool: "{{bool_value}}"
|
||||||
@ -76,10 +78,12 @@ setup:
|
|||||||
"Multisearch template with typed_keys parameter":
|
"Multisearch template with typed_keys parameter":
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
put_template:
|
put_script:
|
||||||
id: registered_template
|
id: registered_template
|
||||||
body:
|
body:
|
||||||
template:
|
script:
|
||||||
|
lang: mustache
|
||||||
|
source:
|
||||||
query:
|
query:
|
||||||
range:
|
range:
|
||||||
integer:
|
integer:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user