# Search template does not work

**URL:** <https://discuss.elastic.co/t/search-template-does-not-work/58317>\
**Category:** Elasticsearch\
**Created:** [August 18, 2016, 6:10am UTC](https://discuss.elastic.co/t/search-template-does-not-work/58317 "2016-08-18T06:10:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddshou](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@ddshou](https://discuss.elastic.co/u/ddshou)\
**Post date:** [August 18, 2016, 6:10am UTC](https://discuss.elastic.co/t/search-template-does-not-work/58317/1 "2016-08-18T06:10:08Z")

</div>

Hello All,  
I am trying to use search template with REST endpoint : GET /\_search/template,and it does work.  
for instance:  
{  
"inline": {  
"query": {  
"match": {  
"title": "{{query\_string}}"  
}  
}  
},  
"params": {  
"query\_string": "search for these words"  
}  
}

But when it comes to condition clause:  
{  
"query": {  
"bool": {  
"must": {  
"match": {  
"line": "{{text}}"  
}  
},  
"filter": {  
{{#line\_no}}  
"range": {  
"line\_no": {  
{{#start}}  
"gte": "{{start}}"  
{{#end}},{{/end}}  
{{/start}}  
{{#end}}  
"lte": "{{end}}"  
{{/end}}  
}  
}  
{{/line\_no}}  
}  
}  
}  
}  
the above template is not valid JSON formate ,so I change it to string ,as the doc showes ([https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-template.html#\_more\_template\_examples](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-template.html#_more_template_examples)),and the complete request is as follow:  
GET /\_search/template  
{  
"inline": "{"query":{"bool":{"must":{"match":{"line":"{{text}}"}},"filter":{{{#line\_no}}"range":{"line\_no":{{{#start}}"gte":"{{start}}"{{#end}},{{/end}}{{/start}}{{#end}}"lte":"{{end}}"{{/end}}}}{{/line\_no}}}}}}",  
"params": {}  
}  
but the result tells error:Failed to compile inline script,Improperly closed variable in query-template:1

however when I store the template as _tmpl.mustache_ under _config/scripts/_ on elasticsearch server,and reference the template file by it's name,then it works correctly.  
Anyone has encountered the confusing problem? Thanks for your sharing!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:27pm UTC](https://discuss.elastic.co/t/search-template-does-not-work/58317/2 "2017-07-05T22:27:04Z")

</div>


