Skip to content

Commit df703dc

Browse files
authored
[DOC] Document {{url}} mustache function (elastic#22549)
This function introduced in elastic#20838 wasn't documented at all. Related to elastic#22459
1 parent 8e8ac5f commit df703dc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

docs/reference/search/search-template.asciidoc

+45
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,51 @@ via the REST API, should be written as a string:
333333
334334
==================================
335335

336+
337+
[float]
338+
===== Encoding URLs
339+
340+
The `{{#url}}value{{/url}}` function can be used to encode a string value
341+
in a HTML encoding form as defined in by the http://www.w3.org/TR/html4/[HTML specification].
342+
343+
As an example, it is useful to encode a URL:
344+
345+
[source,js]
346+
------------------------------------------
347+
GET /_render/template
348+
{
349+
"inline" : {
350+
"query" : {
351+
"term": {
352+
"http_access_log": "{{#url}}{{host}}/{{page}}{{/url}}"
353+
}
354+
}
355+
},
356+
"params": {
357+
"host": "https://www.elastic.co/",
358+
"page": "learn"
359+
}
360+
}
361+
------------------------------------------
362+
// CONSOLE
363+
364+
The previous query will be rendered as:
365+
366+
[source,js]
367+
------------------------------------------
368+
{
369+
"template_output" : {
370+
"query" : {
371+
"term" : {
372+
"http_access_log" : "https%3A%2F%2Fwww.elastic.co%2F%2Flearn"
373+
}
374+
}
375+
}
376+
}
377+
------------------------------------------
378+
// TESTRESPONSE
379+
380+
336381
[float]
337382
[[pre-registered-templates]]
338383
===== Pre-registered template

0 commit comments

Comments
 (0)