# Range filter with nil value

**URL:** <https://discuss.elastic.co/t/range-filter-with-nil-value/32563>\
**Category:** Elasticsearch\
**Created:** [October 20, 2015, 10:52am UTC](https://discuss.elastic.co/t/range-filter-with-nil-value/32563 "2015-10-20T10:52:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramya\_Venkatesh](https://avatars.discourse-cdn.com/v4/letter/r/ebca7d/32.png) [@Ramya\_Venkatesh](https://discuss.elastic.co/u/Ramya_Venkatesh)\
**Post date:** [October 20, 2015, 10:52am UTC](https://discuss.elastic.co/t/range-filter-with-nil-value/32563/1 "2015-10-20T10:52:49Z")

</div>

I'm using the range filter like this for my application (Ignore the syntax)-  
{:range {:created\_at {:gte "from\_date"  
:lte "to\_date"}}}

In some cases one of the dates can be "nil". I'm getting the correct results with the above query, but was wondering if the performance would be better if I split this to be something like-  
{:range {:created\_at  
(if (nil? "from\_date") {:lte "to\_date"})  
(if (nil? "to\_date") {:gte "from\_date"}  
(else {:gte "from\_date"  
:lte "to\_date"})}}

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 20, 2015, 1:19pm UTC](https://discuss.elastic.co/t/range-filter-with-nil-value/32563/2 "2015-10-20T13:19:04Z")

</div>

On the Elasticsearch side it does not make any difference whether you set lte/gte to null or ommit it. I'm not sure if this is also true for the client you are using. Which language client is this? I doubt it makes a difference.

---

<div class="post-metadata">

**Author:** ![Ramya\_Venkatesh](https://avatars.discourse-cdn.com/v4/letter/r/ebca7d/32.png) [@Ramya\_Venkatesh](https://discuss.elastic.co/u/Ramya_Venkatesh)\
**Post date:** [October 21, 2015, 11:35am UTC](https://discuss.elastic.co/t/range-filter-with-nil-value/32563/3 "2015-10-21T11:35:49Z")

</div>

Thanks Christoph. This is in Clojure, modified slightly here. I only wanted to know if cleaning the map for nil values makes sense at all, I guess not.

---

<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:** [July 5, 2017, 11:43pm UTC](https://discuss.elastic.co/t/range-filter-with-nil-value/32563/4 "2017-07-05T23:43:36Z")

</div>


