Search template : unable to close post_Type

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 ?

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