Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting: Deprecate stored search template apis #25437

Merged
merged 3 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions docs/reference/search/multi-search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
}
}
}
}
Expand All @@ -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}}"
}
}
}
}
Expand Down
33 changes: 20 additions & 13 deletions docs/reference/search/search-template.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
}
}
}
}
Expand Down Expand Up @@ -440,7 +442,7 @@ This template can be retrieved by

[source,js]
------------------------------------------
GET _search/template/<templatename>
GET _scripts/<templatename>
------------------------------------------
// CONSOLE
// TEST[continued]
Expand All @@ -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
Expand All @@ -462,7 +469,7 @@ This template can be deleted by

[source,js]
------------------------------------------
DELETE _search/template/<templatename>
DELETE _scripts/<templatename>
------------------------------------------
// CONSOLE
// TEST[continued]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading