Search templates - give entire query as param

I want the entire elasticsearch template query to be given as parameter. The template to be something like

    {
        "lang": "mustache",
        "source": "\{\"query\": {{query_string}}"
      }

And for the query_string to have for example "match_all":{}

However, this does not work. How can it be configured to work?

Hi,
it would be helpful to know what is the exact error you get. But from your snippet, I'd say that you're getting a json_parse_exception, because Mustache is trying to escape the {{query_string}} tag.
If this is the case, you need to avoid automatic escaping by using the triple mustache (see: https://mustache.github.io/mustache.5.html), like in the snippet below:

{
  "lang": "mustache",
  "source": "{\"query\": {{{query_string}}} }"
}

Update:
According to the documentation, this will also work

{
  "lang": "mustache",
  "source": "{\"query\": {{#toJson}}query_string{{/toJson}} }"
}

The issue was a different one - by default, mustache will escape the html characters. So, we just need to unescape them back. With {{#... }}

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