# How to Set Default Integer Value in Search Template

**URL:** <https://discuss.elastic.co/t/how-to-set-default-integer-value-in-search-template/325279>\
**Category:** Elasticsearch\
**Created:** [February 10, 2023, 3:40pm UTC](https://discuss.elastic.co/t/how-to-set-default-integer-value-in-search-template/325279 "2023-02-10T15:40:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [February 10, 2023, 3:40pm UTC](https://discuss.elastic.co/t/how-to-set-default-integer-value-in-search-template/325279/1 "2023-02-10T15:40:19Z")

</div>

I am getting a number\_format\_exception when trying to run a search against a search template containing this snippet of code. It defines a CityID variable and tries to set a wildcard default and the CityID field is defined as an integer in my mapping:

`{{CityID}}{{^CityID}}*{{/CityID}}`

Basically, I am trying to make the CityID field optional in my search template and the string fields work fine when using the \*. Does anyone know what the wildcard default for a integer variable should be? Just as a test I set it to 0 and re-ran the search and it worked but did not return any results because I have no Cities with a CityID of 0 and obviously I cannot make that the default. I just wanted to confirm that the definition is in fact expecting an integer value. Any help would be appreciated. Thanks.

Kevin

---

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [February 23, 2023, 6:58pm UTC](https://discuss.elastic.co/t/how-to-set-default-integer-value-in-search-template/325279/2 "2023-02-23T18:58:53Z")

</div>

This issue is resolved and it was fixed by changing my search template definition for CityID to this:

`{{#CityID}}{{.}}{{/CityID}}{{^CityID}}0{{/CityID}}`

This basically says use the CityID value if it is passed into the search template (represented by the period place holder) or use the value of 0 if no value is passed. This works for me because this portion of the search template is in a should clause and I have no Cities with a CityID of 0. Just thought I would post an update in case anyone else runs into this issue.

Kevin

---

<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 23, 2023, 6:59pm UTC](https://discuss.elastic.co/t/how-to-set-default-integer-value-in-search-template/325279/3 "2023-03-23T18:59:31Z")

</div>

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