Skip to content
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
123 changes: 123 additions & 0 deletions docs/reference/search/search-template.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,89 @@ which is rendered as:
}
------------------------------------------


[float]
===== Concatenating array of values

The `{{#join}}array{{/join}}` function can be used to concatenate the
values of an array as a comma delimited string:

[source,js]
------------------------------------------
GET /_search/template
{
"inline": {
"query": {
"match": {
"emails": "{{#join}}emails{{/join}}"
}
}
},
"params": {
"emails": [ "[email protected]", "[email protected]" ]
}
}
------------------------------------------

which is rendered as:

[source,js]
------------------------------------------
{
"query" : {
"match" : {
"emails" : "[email protected],[email protected]"
}
}
}
------------------------------------------

The function also accepts a custom delimiter:

[source,js]
------------------------------------------
GET /_search/template
{
"inline": {
"query": {
"range": {
"born": {
"gte" : "{{date.min}}",
"lte" : "{{date.max}}",
"format": "{{#join delimiter='||'}}date.formats{{/join delimiter='||'}}"
}
}
}
},
"params": {
"date": {
"min": "2016",
"max": "31/12/2017",
"formats": ["dd/MM/yyyy", "yyyy"]
}
}
}
------------------------------------------

which is rendered as:

[source,js]
------------------------------------------
{
"query" : {
"range" : {
"born" : {
"gte" : "2016",
"lte" : "31/12/2017",
"format" : "dd/MM/yyyy||yyyy"
}
}
}
}

------------------------------------------


[float]
===== Default values

Expand Down Expand Up @@ -140,6 +223,46 @@ for `end`:
}
------------------------------------------

[float]
===== Converting parameters to JSON

The `{{toJson}}parameter{{/toJson}}` function can be used to convert parameters
like maps and array to their JSON representation:

[source,js]
------------------------------------------
{
"inline": "{\"query\":{\"bool\":{\"must\": {{#toJson}}clauses{{/toJson}} }}}",
"params": {
"clauses": [
{ "term": "foo" },
{ "term": "bar" }
]
}
}
------------------------------------------

which is rendered as:

[source,js]
------------------------------------------
{
"query" : {
"bool" : {
"must" : [
{
"term" : "foo"
},
{
"term" : "bar"
}
]
}
}
}
------------------------------------------


[float]
===== Conditional clauses

Expand Down
Loading