# Search template : unable to close post\_Type

**URL:** <https://discuss.elastic.co/t/search-template-unable-to-close-post-type/222212>\
**Category:** Elasticsearch\
**Created:** [March 5, 2020, 7:15am UTC](https://discuss.elastic.co/t/search-template-unable-to-close-post-type/222212 "2020-03-05T07:15:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Gachet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeremy_gachet/32/50275_2.png) [@Jeremy\_Gachet](https://discuss.elastic.co/u/Jeremy_Gachet)\
**Post date:** [March 5, 2020, 7:15am UTC](https://discuss.elastic.co/t/search-template-unable-to-close-post-type/222212/1 "2020-03-05T07:15:41Z")

</div>

Hello everyone,  
I'm trying to add a conditional tag to my mustache script.  
Everything works well without it but as soon as I add it I got an error :

Here is my script

```
POST _scripts/search-all-v2
{
  "script": {
    "lang": "mustache",
    "source": " { \"query\": { \"bool\": { \"filter\": [{{#post_type}} { \"must\": { \"match\": { \"post_type\": \"{{post_type}\" } } } {{/post_type}}], \"must\": [], \"should\": [{ \"multi_match\": { \"query\": \"{{search_term}}\", \"type\": \"phrase\", \"fields\": [ \"body_unified\"] } } ] } }, \"_source\": [\"body_unified\", \"createdbyid\", \"parentid\", \"likecount\", \"commentcount\", \"post_type\"], \"highlight\": { \"fields\": { \"body_unified\": {} }, \"order\": \"score\" }} ",
    "options": {
      "content_type": "application/json; charset=UTF-8"
    }
  }
}

```

Here is my query  
GET posts-dev/\_search/template  
{  
"id": "search-all-v2",  
"params": {  
"search\_term": "manage",  
"post\_type": "comment"  
}  
}

And the error is

```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "Failed to close 'post_type' tag @[query-template:1]",
        "script_stack" : [],
        "script" : " { \"query\": { \"bool\": { \"filter\": [{{#post_type}} { \"must\": { \"match\": { \"post_type\": \"{{post_type}\" } } } {{/post_type}}], \"must\": [], \"should\": [{ \"multi_match\": { \"query\": \"{{search_term}}\", \"type\": \"phrase\", \"fields\": [ \"body_unified\"] } } ] } }, \"_source\": [\"body_unified\", \"createdbyid\", \"parentid\", \"likecount\", \"commentcount\", \"post_type\"], \"highlight\": { \"fields\": { \"body_unified\": {} }, \"order\": \"score\" }} ",
        "lang" : "mustache"
      }
    ],
    "type" : "script_exception",
    "reason" : "Failed to close 'post_type' tag @[query-template:1]",
    "script_stack" : [],
    "script" : " { \"query\": { \"bool\": { \"filter\": [{{#post_type}} { \"must\": { \"match\": { \"post_type\": \"{{post_type}\" } } } {{/post_type}}], \"must\": [], \"should\": [{ \"multi_match\": { \"query\": \"{{search_term}}\", \"type\": \"phrase\", \"fields\": [ \"body_unified\"] } } ] } }, \"_source\": [\"body_unified\", \"createdbyid\", \"parentid\", \"likecount\", \"commentcount\", \"post_type\"], \"highlight\": { \"fields\": { \"body_unified\": {} }, \"order\": \"score\" }} ",
    "lang" : "mustache",
    "caused_by" : {
      "type" : "mustache_exception",
      "reason" : "Failed to close 'post_type' tag @[query-template:1]"
    }
  },
  "status" : 400
}

```

I just don't understand the issue.  
Could you help me ?

---

<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:** [April 2, 2020, 7:15am UTC](https://discuss.elastic.co/t/search-template-unable-to-close-post-type/222212/2 "2020-04-02T07:15:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
