From e56d85439c242dee8ce1f8fec9fd59872dd2efb9 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Fri, 31 Oct 2014 15:27:57 +0100 Subject: [PATCH] Update search-template.asciidoc Clarified using the conditional clause template example as a string --- docs/reference/search/search-template.asciidoc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/reference/search/search-template.asciidoc b/docs/reference/search/search-template.asciidoc index 978bf27e162..025a27e9e00 100644 --- a/docs/reference/search/search-template.asciidoc +++ b/docs/reference/search/search-template.asciidoc @@ -163,6 +163,7 @@ We could write the query as: [source,js] ------------------------------------------ { + "query": { "filtered": { "query": { "match": { @@ -185,6 +186,7 @@ We could write the query as: {{/line_no}} <2> } } + } } ------------------------------------------ <1> Fill in the value of param `text` @@ -196,11 +198,22 @@ We could write the query as: <6> Include the `lte` clause only if `line_no.end` is specified <7> Fill in the value of param `line_no.end` +[NOTE] +================================== As written above, this template is not valid JSON because it includes the -_section_ markers like `{{#line_no}}`. For this reason, the template -can only be written as a string. +_section_ markers like `{{#line_no}}`. For this reason, the template should +either be stored in a file (see <>) or, when used +via the REST API, should be written as a string: + +[source,json] +-------------------- +"template": "{\"query\":{\"filtered\":{\"query\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}" +-------------------- + +================================== [float] +[[pre-registered-templates]] ===== Pre-registered template You can register search templates by storing it in the `config/scripts` directory, in a file using the `.mustache` extension.