# Search Template with float parameters

**URL:** <https://discuss.elastic.co/t/search-template-with-float-parameters/93624>\
**Category:** Elasticsearch\
**Created:** [July 18, 2017, 4:22pm UTC](https://discuss.elastic.co/t/search-template-with-float-parameters/93624 "2017-07-18T16:22:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![p\_tarte](https://avatars.discourse-cdn.com/v4/letter/p/ecc23a/32.png) [@p\_tarte](https://discuss.elastic.co/u/p_tarte)\
**Post date:** [July 18, 2017, 4:22pm UTC](https://discuss.elastic.co/t/search-template-with-float-parameters/93624/1 "2017-07-18T16:22:23Z")

</div>

Hello,

I'm trying to build a search template that will return records having a specific field greater or equal to a specific float value. My template looks like this:

```
POST _search/template/SearchMetricGTE
{
  "template": {
    "size": "{{NumberOfHits}}",
    "query": {
      "bool": {
        "filter": [
          {
            "range": {
              "@timestamp": {
                "gte": "{{DateExpression}}",
                "time_zone": "+00:00"
              }
            }
          },
          {
            "range": {
              "{{PerfmonCounter}}": {
                "gte": "{{PerfmonCounterValue}}"
              }
            }
          }
        ]
      }
    }
  }
}

```

I'm trying to use it like that:

```
GET metric_gcs_server/_search/template
{
  "id" : "SearchMetricGTE",
  "params" : {
    "NumberOfHits" : "10",
    "DateExpression" : "now-30m",
    "PerfmonCounter" : "windows.perfmon.CPU Client Service",
    "PerfmonCounterValue" : 0
		  }
}

```

If PerfmonCounterValue is set with an integer value (as depicted above), everything works as expected. However, if I set it with a float value, 0.25 for example, I receive an error message:

```
{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n \"bool\" : {\n \"filter\" : [\n {\n \"range\" : {\n \"@timestamp\" : {\n \"from\" : \"now-30m\",\n \"to\" : null,\n \"include_lower\" : true,\n \"include_upper\" : true,\n \"time_zone\" : \"UTC\",\n \"boost\" : 1.0\n }\n }\n },\n {\n \"range\" : {\n \"windows.perfmon.CPU Client Service\" : {\n \"from\" : \"0.25\",\n \"to\" : null,\n \"include_lower\" : true,\n \"include_upper\" : true,\n \"boost\" : 1.0\n }\n }\n }\n],\n \"disable_coord\" : false,\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}",
        "index_uuid": "5cF-ymppQqCpgbMS3KhhzQ",
        "index": "metric_gcs_server"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "metric_gcs_server",
        "node": "D2qWwLwzTzmTbRNm28QLIg",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n \"bool\" : {\n \"filter\" : [\n {\n \"range\" : {\n \"@timestamp\" : {\n \"from\" : \"now-30m\",\n \"to\" : null,\n \"include_lower\" : true,\n \"include_upper\" : true,\n \"time_zone\" : \"UTC\",\n \"boost\" : 1.0\n }\n }\n },\n {\n \"range\" : {\n \"windows.perfmon.CPU Client Service\" : {\n \"from\" : \"0.25\",\n \"to\" : null,\n \"include_lower\" : true,\n \"include_upper\" : true,\n \"boost\" : 1.0\n }\n }\n }\n],\n \"disable_coord\" : false,\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}",
          "index_uuid": "5cF-ymppQqCpgbMS3KhhzQ",
          "index": "metric_gcs_server",
          "caused_by": {
            "type": "number_format_exception",
            "reason": "For input string: \"0.25\""
          }
        }
      }
    ]
  },
  "status": 400
}

```

It seems that since my value contains a dot, it gets translated to an string with escaped double quotes and the conversion fails. The examples provided for search template always use integer and I did not find anything with google on this specific use case.

Is it a limitation of the mustache scripting language? Is there a way to make it work?

Thanks,  
Pierre-Luc

---

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [July 18, 2017, 4:54pm UTC](https://discuss.elastic.co/t/search-template-with-float-parameters/93624/2 "2017-07-18T16:54:58Z")

</div>

Can you please put the code in code block. It is very hard to read.

---

<div class="post-metadata">

**Author:** ![p\_tarte](https://avatars.discourse-cdn.com/v4/letter/p/ecc23a/32.png) [@p\_tarte](https://discuss.elastic.co/u/p_tarte)\
**Post date:** [July 18, 2017, 5:10pm UTC](https://discuss.elastic.co/t/search-template-with-float-parameters/93624/3 "2017-07-18T17:10:57Z")

</div>

Added code section for readability.

---

<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:** [August 15, 2017, 5:11pm UTC](https://discuss.elastic.co/t/search-template-with-float-parameters/93624/4 "2017-08-15T17:11:18Z")

</div>

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