# Conditional clause not working

**URL:** <https://discuss.elastic.co/t/conditional-clause-not-working/82877>\
**Category:** Elasticsearch\
**Created:** [April 19, 2017, 11:48am UTC](https://discuss.elastic.co/t/conditional-clause-not-working/82877 "2017-04-19T11:48:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![usund](https://avatars.discourse-cdn.com/v4/letter/u/d26b3c/32.png) [@usund](https://discuss.elastic.co/u/usund)\
**Post date:** [April 19, 2017, 11:48am UTC](https://discuss.elastic.co/t/conditional-clause-not-working/82877/1 "2017-04-19T11:48:46Z")

</div>

Hi,  
I have a scenario where I have to exclude range filter if price is not passed in the params to the template.  
something like

{  
"query": {  
"bool": {  
"must": {  
"match": {  
"name": "{{query\_keywords}}"  
}  
},  
"filter":{  
"bool":{  
"must" :[  
{{#price}}  
{"range" : {"price" : {"gte": "{{min}}","lte":"{{max}}}}}  
{{/price}}  
]  
}  
}

```
		}
	}

```

}

but I am not able to achieve this. so I am setting default value if price is not set like below  
{  
"query": {  
"bool": {  
"must": {  
"match": {  
"name": "{{query\_keywords}}"  
}  
},  
"filter":{  
"bool":{  
"must" :[  
{"range" : {"price" : {"gte": "{{price.min}}{{^price.min}}0{{/price.min}}"}}}  
]  
}  
}

```
		}
	}

```

}

This will hamper the performance in production. So can anyone suggest what has to be done. The example given the ES doc doesnt work. How to achieve this? Please help.

---

<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 17, 2017, 11:55am UTC](https://discuss.elastic.co/t/conditional-clause-not-working/82877/2 "2017-05-17T11:55:43Z")

</div>

Closed on May 17, 2017, 11:55am UTC

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