# Cannot parse numeric values in a search template

**URL:** <https://discuss.elastic.co/t/cannot-parse-numeric-values-in-a-search-template/247088>\
**Category:** Elasticsearch\
**Created:** [September 1, 2020, 12:22pm UTC](https://discuss.elastic.co/t/cannot-parse-numeric-values-in-a-search-template/247088 "2020-09-01T12:22:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mekanix](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mekanix](https://discuss.elastic.co/u/mekanix)\
**Post date:** [September 1, 2020, 12:22pm UTC](https://discuss.elastic.co/t/cannot-parse-numeric-values-in-a-search-template/247088/1 "2020-09-01T12:22:23Z")

</div>

Fx. if I take the example from [Elasticsearch Reference [7.9] » REST APIs » Search APIs » Search Template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#search-template) and render it I get

```auto
POST _render/template
{
  "source" : {
    "query": { "match" : { "{{my_field}}" : "{{my_value}}" } },
    "size" : "{{my_size}}"
  },
  "params" : {
    "my_field" : "message",
    "my_value" : "foo",
    "my_size" : 5
  }
}

```

Becomes

```auto
{
  "template_output" : {
    "query" : {
      "match" : {
        "message" : "foo"
      }
    },
    "size" : "5"
  }
}

```

As you can see the INTEGER 5 becomes the string "5".

So document is a bit misleading as it is implied it can handle numeric values.

The only way around this I can think of is to drop working with JSON and turn it into a string (mustache and JSON don't really mix).

Any other options?

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [September 3, 2020, 2:59pm UTC](https://discuss.elastic.co/t/cannot-parse-numeric-values-in-a-search-template/247088/2 "2020-09-03T14:59:31Z")

</div>

Hey Bjarne,

Indeed the documentation you referred to is not fully accurate and we'll fix that (thanks for pointing out!).

One way to workaround the issue you've mentioned is to write the query as a string, this way you can refer to `{{my_size}}` without double-quotes, which will produce an integer, without breaking JSON syntax. For instance:

```auto
POST _render/template
{
  "source" : "{ \"query\": { \"match\" : { \"{{my_field}}\" : \"{{my_value}}\" } }, \"size\" : {{my_size}} }",
  "params" : {
    "my_field" : "message",
    "my_value" : "foo",
    "my_size" : 5
  }
}

```

Best

---

<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:** [October 1, 2020, 2:59pm UTC](https://discuss.elastic.co/t/cannot-parse-numeric-values-in-a-search-template/247088/3 "2020-10-01T14:59:33Z")

</div>

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