Template _search unexpected character

Elasticsearch version: 6.3.2

I have a search template, which I am using to loop over an array of strings but when I _search/template I get an error saying Unexpected character ('{' (code 123)): was expecting comma to separate Array entries. However if I _render/template then copy it and just use _search it works perfectly.

Template:

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must_not": [
              {{#keywords}}
              {
                "term": {
                  "title": "{{.}}"
                }
              },
              {
                "term": {
                  "categories.name.raw": "{{.}}"
                }
              }
              {{/keywords}}
            ],
            "minimum_should_match": "1",
            "boost": 0.2
          }
        }
      ]
    }
  },
  "size": 0
}

Params:

{
  "id": "products_test",
  "params": {
    "params": [
      "book",
      "cover"
    ]
  }
}

_render result:

{
  "template_output": {
    "query": {
      "bool": {
        "filter": [
          {
            "bool": {
              "must_not": [
                {
                  "term": {
                    "title": "book"
                  }
                },
                {
                  "term": {
                    "categories.name.raw": "book"
                  }
                },
                {
                  "term": {
                    "title": "cover"
                  }
                },
                {
                  "term": {
                    "categories.name.raw": "cover"
                  }
                }
              ],
              "minimum_should_match": "1",
              "boost": 0.2
            }
          }
        ]
      }
    },
    "size": 0
  }
}

I can't see anything I'm doing wrong but I might have missed something.

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