search-template
post/get/delete/render/search template
POST _scripts/test_template
{
"script": {
"lang": "mustache",
"source": {
"query": {
"term": {
"{{param_key}}": "{{param_value}}"
}
}
}
}
}
GET _scripts/test_template
DELETE _scripts/test_template
GET _render/template
{
"id": "test_template",
"params": {
"param_key": "geo.src",
"param_value":"IN"
},
"explain":true
}
GET kibana_sample_data_logs/_search?size=1
GET kibana_sample_data_logs/_search/template
{
"id": "test_template",
"params": {
"param_key": "geo.src",
"param_value":"IN"
},
"explain":true
}
GET _msearch/template
{
"index": "kibana_sample_data_logs"
}
{
"id": "test_template",
"params": {
"param_key": "geo.src",
"param_value": "IN"
}
}
{
"index": "kibana_sample_data_logs"
}
{
"id": "test_template",
"params": {
"param_key": "geo.dest",
"param_value": "IN"
}
}
render
POST _scripts/test_template
{
"script": {
"lang": "mustache",
"source": {
"query": {
"term": {
"{{param_key}}": "{{param_value}}"
}
}
}
}
}
GET _render/template
{
"source": {
"query": {
"term": {
"{{param_key}}": "{{param_value}}"
}
}
},
"params": {
"param_key":"age",
"param_value": 32
}
}
GET _render/template
{
"id": "test_template",
"params": {
"param_key":"age",
"param_value": 32
}
}
{{#toJson}}{{/toJson}}
GET _search/template
{
"source": """{ "query": { "terms": {{#toJson}}statuses{{/toJson}} }}""",
"params": {
"statuses": {
"age": [
"32",
"34"
]
}
}
}
GET _render/template
{
"source": """{ "query": { "terms": {{#toJson}}statuses{{/toJson}} }}""",
"params": {
"statuses": {
"age": [
"32",
"34"
]
}
}
}
GET _search/template
{
"source": """{"query":{"bool":{"must": {{#toJson}}clauses{{/toJson}} }}}""",
"params": {
"clauses": [
{
"match": {
"firstname": "Amber"
}
},
{
"match": {
"lastname": "Duke"
}
}
]
}
}
{{#join}}array{{/join}}
GET _search/template
{
"source": {
"query": {
"match": {
"emails": "{{#join}}emails{{/join}}"
}
}
},
"params": {
"emails": [
"amberduke@pyrami.com",
"cottonchristensen@prowaste.com"
]
}
}
GET _render/template
{
"source": {
"query": {
"match": {
"emails": "{{#join}}emails{{/join}}"
}
}
},
"params": {
"emails": [
"amberduke@pyrami.com",
"cottonchristensen@prowaste.com"
]
}
}
GET _render/template
{
"source": {
"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"
]
}
}
}
GET _search/template
{
"source": {
"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"
]
}
}
}
{{var}}{{^var}}defaultValue{{/var}}
GET _render/template
{
"source": {
"query": {
"range": {
"age": {
"gte": "{{start}}",
"lte": "{{end}}{{^end}}36{{/end}}"
}
}
}
},
"params": {
"start": 35
}
}
GET _render/template
{
"source": {
"query": {
"range": {
"age": {
"gte": "{{start}}",
"lte": "{{end}}{{^end}}36{{/end}}"
}
}
}
},
"params": {
"start": 35,
"end": 38
}
}
# end default is 36
GET _search/template
{
"source": {
"query": {
"range": {
"age": {
"gte": "{{start}}",
"lte": "{{end}}{{^end}}36{{/end}}"
}
}
}
},
"params": {
"start": 35
}
}
{{#url}}value{{/url}}
GET _render/template
{
"source" : {
"query" : {
"term": {
"http_access_log": "{{#url}}{{host}}/{{page}}{{/url}}"
}
}
},
"params": {
"host": "https://www.elastic.co/",
"page": "learn"
}
}
GET _search/template
{
"source" : {
"query" : {
"term": {
"http_access_log": "{{#url}}{{host}}/{{page}}{{/url}}"
}
}
},
"params": {
"host": "https://www.elastic.co/",
"page": "learn"
}
}