# Search template with compare equal

**URL:** <https://discuss.elastic.co/t/search-template-with-compare-equal/358390>\
**Category:** Elasticsearch\
**Created:** [April 29, 2024, 4:47am UTC](https://discuss.elastic.co/t/search-template-with-compare-equal/358390 "2024-04-29T04:47:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![h\_ng\_d\_ng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/h_ng_d_ng/32/125786_2.png) [@h\_ng\_d\_ng](https://discuss.elastic.co/u/h_ng_d_ng)\
**Post date:** [April 29, 2024, 4:47am UTC](https://discuss.elastic.co/t/search-template-with-compare-equal/358390/1 "2024-04-29T04:47:21Z")

</div>

Hi  
i am trying using search template to compare equal string to return specific records, it looks like this  
{{#equals false isJobInProgress}}  
,{"bool":{"should":[{"term":{"is\_job\_in\_progress":false}},{"bool":{"must\_not":{"exists":{"field":"is\_job\_in\_progress"}}}}]}}  
{{/equals}}  
{{#equals true isJobInProgress}}  
,{"term":{"is\_job\_in\_progress":true}}  
{{/equals}}  
but it return me error ResponseError: script\_exception: [script\_exception] Reason: Mismatched start/end tags: equals false isJobInProgress != equals in query-template:1 @[query-template:1], i am not sure the equal is correct syntax ot not , pls help

---

<div class="post-metadata">

**Author:** ![canelia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/canelia/32/141857_2.png) [@canelia](https://discuss.elastic.co/u/canelia)\
**Post date:** [April 29, 2024, 5:57am UTC](https://discuss.elastic.co/t/search-template-with-compare-equal/358390/2 "2024-04-29T05:57:31Z")

</div>

can you share params?

---

<div class="post-metadata">

**Author:** ![h\_ng\_d\_ng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/h_ng_d_ng/32/125786_2.png) [@h\_ng\_d\_ng](https://discuss.elastic.co/u/h_ng_d_ng)\
**Post date:** [April 29, 2024, 6:30am UTC](https://discuss.elastic.co/t/search-template-with-compare-equal/358390/3 "2024-04-29T06:30:18Z")

</div>

i think i found out a solution for this already, firstly, the "equals" does not work directly to compare this way, i have to create other params call "equals" in client side and do comparison and return true or fasle.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [April 29, 2024, 7:24am UTC](https://discuss.elastic.co/t/search-template-with-compare-equal/358390/4 "2024-04-29T07:24:11Z")

</div>

conditions examples: [Search templates | Elasticsearch Guide [8.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#search-template-use-conditions)

search templates are not great for conditionals and suggest you try and push your logic into the API that calls the search template and provide only params to be replaced in the search template. If you do need conditionals then pass params which are strictly non optional boolean values. This makes it more testable on your side.

Joe

---

<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:** [May 27, 2024, 7:24am UTC](https://discuss.elastic.co/t/search-template-with-compare-equal/358390/5 "2024-05-27T07:24:22Z")

</div>

Closed on May 27, 2024, 7:24am UTC

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