Browse Source

[Docs] updated the search template and query template docs

Boaz Leskes 11 years ago
parent
commit
fc8dc3f733

+ 4 - 4
docs/reference/query-dsl/queries/template-query.asciidoc

@@ -42,7 +42,7 @@ GET /_search
 <1> New line characters (`\n`) should be escaped as `\\n` or removed,
     and quotes (`"`) should be escaped as `\\"`.
 
-You can register a template by storing it in the `config/scripts` directory.
+You can register a template by storing it in the `config/scripts` directory, in a file using the `.mustache` extension.
 In order to execute the stored template, reference it by name in the `query`
 parameter:
 
@@ -62,7 +62,7 @@ GET /_search
 }
 
 ------------------------------------------
-<1> Name of the the query template in `config/scripts/`.
+<1> Name of the the query template in `config/scripts/`, i.e., `storedTemplate.mustache`.
 
 Templating is based on Mustache. For simple token substitution all you provide
 is a query containing some variable that you want to substitute and the actual
@@ -95,6 +95,6 @@ which is then turned into:
 }
 ------------------------------------------
 
-There is also a dedicated `template` endpoint, which allows you to specify the template query directly.
-You can use the `/_search/template` endpoint for that. Please see <<search-template>> for more details.
+There is also a dedicated `template` endpoint, allows you to template an entire search request.
+Please see <<search-template>> for more details.
 

+ 21 - 4
docs/reference/search/search-template.asciidoc

@@ -3,18 +3,16 @@
 
 coming[1.1.0]
 
-Using a query template allows to use the mustache language to pre render search requests,
+The `/_search/template` endpoint allows to use the mustache language to pre render search requests,
 before they are executed and fill existing templates with template parameters.
 
-You can use the `/_search/template` endpoint for that.
-
 [source,js]
 ------------------------------------------
 GET /_search/template
 {
     "template" : {
       "query": { "match" : { "{{my_field}}" : "{{my_value}}" } },
-      "size" : {{my_size}}
+      "size" : "{{my_size}}"
     },
     "params" : {
         "my_field" : "foo",
@@ -204,3 +202,22 @@ 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.
 
+[float]
+===== Pre-registered template
+
+You can register search templates by storing it in the `config/scripts` directory, in a file using the `.mustache` extension.
+In order to execute the stored template, reference it by it's name under the `template` key:
+
+
+[source,js]
+------------------------------------------
+GET /_search/template
+{
+    "template": "storedTemplate" <1>,
+    "params": {
+        "query_string": "search for these words"
+    }
+}
+------------------------------------------
+
+<1> Name of the the query template in `config/scripts/`, i.e., `storedTemplate.mustache`.