# Conditional Clauses not working with Pre-registered template

**URL:** <https://discuss.elastic.co/t/conditional-clauses-not-working-with-pre-registered-template/117094>\
**Category:** Elasticsearch\
**Created:** [January 25, 2018, 5:41pm UTC](https://discuss.elastic.co/t/conditional-clauses-not-working-with-pre-registered-template/117094 "2018-01-25T17:41:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_Fazackerley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_fazackerley/32/47012_2.png) [@Jack\_Fazackerley](https://discuss.elastic.co/u/Jack_Fazackerley)\
**Post date:** [January 25, 2018, 5:41pm UTC](https://discuss.elastic.co/t/conditional-clauses-not-working-with-pre-registered-template/117094/1 "2018-01-25T17:41:50Z")

</div>

Hi,

From the [Docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#_conditional_clauses) it says that using conditional clauses will cause JSON to be invalid so the JSON would have to be a string but it also says that Pre-registered templates can be used instead with no note of it needing to be converted to a string.

Am I misinterpreting this? If not, how is it possible to use a pre-registered template with conditional clauses? Each time I try and create a template I get the following in response:

```
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[stored script source] failed to parse field [source]",
        "line": 6,
        "col": 26
      }
    ],
    "type": "parsing_exception",
    "reason": "[stored script source] failed to parse field [source]",
    "line": 6,
    "col": 26,
    "caused_by": {
      "type": "unchecked_i_o_exception",
      "reason": "com.fasterxml.jackson.core.JsonParseException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2d9b1399; line: 7, column: 20]",
      "caused_by": {
        "type": "json_parse_exception",
        "reason": "Unexpected character ('{' (code 123)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2d9b1399; line: 7, column: 20]"
      }
    }
  },
  "status": 400
}

```

And as an example JSON I am using the following:

```
POST _scripts/test
{
    "script": {
        "lang": "mustache",
        "source": {
            "query": {
                "match": {
                  {{#something}}
                    "title": "{{query_string}}"
                  {{/something}}
                }
            }
        }
    }
}

```

Any help with this would be much appreciated, Thanks.

---

<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:** [February 22, 2018, 5:41pm UTC](https://discuss.elastic.co/t/conditional-clauses-not-working-with-pre-registered-template/117094/2 "2018-02-22T17:41:51Z")

</div>

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