diff --git a/docs/reference/search/multi-search.asciidoc b/docs/reference/search/multi-search.asciidoc index 61e975d4ae244..c68cf0daaf55a 100644 --- a/docs/reference/search/multi-search.asciidoc +++ b/docs/reference/search/multi-search.asciidoc @@ -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}}" + } } } } diff --git a/docs/reference/search/search-template.asciidoc b/docs/reference/search/search-template.asciidoc index ee7fa61885f03..cc2b9b7cf8f32 100644 --- a/docs/reference/search/search-template.asciidoc +++ b/docs/reference/search/search-template.asciidoc @@ -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/ +POST _scripts/ { - "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/ +GET _scripts/ ------------------------------------------ // CONSOLE // TEST[continued] @@ -450,10 +452,15 @@ which is rendered as: [source,js] ------------------------------------------ { - "_id" : "", - "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": "", + "found": true } ------------------------------------------ // TESTRESPONSE @@ -462,7 +469,7 @@ This template can be deleted by [source,js] ------------------------------------------ -DELETE _search/template/ +DELETE _scripts/ ------------------------------------------ // CONSOLE // TEST[continued] 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 index 23b6c2869593a..2db57c6563136 100644 --- 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 @@ -20,6 +20,8 @@ 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 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 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 index 1fea2ca8cafad..3a69a9e25f4e0 100644 --- 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 @@ -22,6 +22,8 @@ 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 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 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 index 9a6c5f7f09121..e6e6e1392896d 100644 --- 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 @@ -23,6 +23,8 @@ 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 @@ 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 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 f0c4e2ca2710b..4e1ce5b1b4eef 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 @@ -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" diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml index b631b9920ca14..adf8388da8757 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml @@ -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: diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml index 14b17b07a4d46..f90850c361d06 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml @@ -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: diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml index f179e0fc3a97f..8e1829955ad05 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml @@ -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: diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml index 98adc5ab4c29b..6fef715df10a2 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml @@ -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 }