title: How use tojson in pre-registered mushache template in Elasticsearch
body: <p>How use terms in pre-registered mushache template in Elasticsearch</p>
  
  <p>Hi,</p>
  
  <p>I use the Elasticsearch v5.6.3. In the kibana Console, I attempt to save a search template with a term query.</p>
  
  <pre><code>POST _scripts/test-json
  {
    "script": {
      "lang": "mustache",
      "source": {"query": {"filter": {"bool": {"must": [{"terms": {"beat.hostname": {{#tojson}}hostname{{/tojson}} } }] } } } }
    }
  }
  </code></pre>
  
  <p>But I got a syntax error without the double quote.</p>
  
  <p>I saw the issue in github.
  <a href="https://github.com/elastic/elasticsearch/issues/21648" rel="nofollow noreferrer">https://github.com/elastic/elasticsearch/issues/21648</a></p>
  
  <p>I changed the template like the sample in this issue, it's no syntax error. But I can not get the result.</p>
  
  <pre><code>POST _scripts/test-json
  {
    "script": {
      "lang": "mustache",
      "source": {"query": {"filter": {"bool": {"must": [{"terms": {"beat.hostname": ["{{hostname}}"] } }] } } } }
    }
  }
  </code></pre>
  
  <p>And then I changed the template:</p>
  
  <pre><code>POST _scripts/test-json
  {
    "script": {
      "lang": "mustache",
      "source": {"query": {"filter": {"bool": {"must": [{"terms": {"beat.hostname": ["{{#tojson}}hostname{{/tojson}}}}"] } }] } } } }
    }
  }
  </code></pre>
  
  <p>After call is, I got a runtime error.</p>
  
  <pre><code>  {
      "type": "json_parse_exception",
      "reason": "Unexpected character ('h' (code 104)): was expecting comma to separate Array entries\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@396f6738; line: 1, column: 190]"
    }
  </code></pre>
  
  <p>How could I send some params for the terms in a pre-registered search template?</p>
  
  <p>Thank you.</p>