# Using Triple Quotes in Elastic Templates

**URL:** <https://discuss.elastic.co/t/using-triple-quotes-in-elastic-templates/218474>\
**Category:** Elasticsearch\
**Created:** [February 9, 2020, 4:16pm UTC](https://discuss.elastic.co/t/using-triple-quotes-in-elastic-templates/218474 "2020-02-09T16:16:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![index](https://avatars.discourse-cdn.com/v4/letter/i/db5fbb/32.png) [@index](https://discuss.elastic.co/u/index)\
**Post date:** [February 9, 2020, 4:16pm UTC](https://discuss.elastic.co/t/using-triple-quotes-in-elastic-templates/218474/1 "2020-02-09T16:16:21Z")

</div>

I am using templating to do query and rescoring work. The rescoring happens based on couple of values that are index in the document. Due to the logic that needs to happen based on the value in the document I decided to use **painless** instead of **ternary operator**. Especially its hard to achieve the logic in ternary and also readability get really low.

I fallowed the documentation in Elasticsearch to get an understanding of **painless** [Elastic Painless Walkthrough](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-walkthrough.html)

But when I render the template It complains at the end of the closing triple quotes. I was unable to really find a clear answer. This looks like clearly due to invalid **JSON** but according the elastic documentation this should be working. My elastic version is 6.1-6.2.

Stackoverflow has a similar question:  
[Stackoverflow Question](https://stackoverflow.com/questions/55931073/elasticsearch-painless-error-when-using-three-quotes-unexpected-character)

Kibana forum  
[Kibana Forum Triple Quotes](https://discuss.elastic.co/t/triple-quotes/111902)

Here is the error I am getting when I am rendering:

> parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 232, column 27

Here is the template:

```
{
  "query": {
    "rescore_query": {
      "function_score": {
        "boost_mode":"sum",
        "score_mode": "sum",
        "functions":[{
            "script_score" : {
              "script" : {
                  "lang":"painless",
                  {{#rescore.my_params.params}}
                    "params": {
                      "x": {{rescore.my_params.params.x}},
                      "y": {{rescore.my_params.params.y}},
                      "z": {{rescore.my_params.params.z}}
                    },
                  {{/rescore.my_params.params}}
                  {{#rescore.my_params.my_function}}
                    "source":"""
                      double doc_x = 0.0;
                      double doc_y = 0.0;
                      if (doc['doc_x'].empty) {
                          doc_x = 0.0;
                      } else {
                          doc_x = doc['doc_x'].value;
                      }
                      if (doc['doc_y'].empty) {
                          doc_y = params.y;
                      } else {
                          doc_y = doc['doc_y'].value;
                      }
                      double final_value = 2 * (doc_x + doc_y);
                      return final_value;
                    """ {{! here is where the error is getting thrown}}
                  {{/rescore.my_params.my_function}}
              }
            }
        }]
      }
    }

```

---

<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:** [March 8, 2020, 4:29pm UTC](https://discuss.elastic.co/t/using-triple-quotes-in-elastic-templates/218474/2 "2020-03-08T16:29:00Z")

</div>

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