# Is there any way to set default date range in elasticsearch

**URL:** <https://discuss.elastic.co/t/is-there-any-way-to-set-default-date-range-in-elasticsearch/148963>\
**Category:** Elasticsearch\
**Created:** [September 18, 2018, 10:57am UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-default-date-range-in-elasticsearch/148963 "2018-09-18T10:57:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BleedCode](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@BleedCode](https://discuss.elastic.co/u/BleedCode)\
**Post date:** [September 18, 2018, 10:57am UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-default-date-range-in-elasticsearch/148963/1 "2018-09-18T10:57:23Z")

</div>

Is there any way in elasticsearch to set a default date range if to and from fields are null. Like whenever to and from are empty, then elasticsearch should perform search on the basis of defined default range. I have written a query but it only works in the case if to and from is defined:

```auto
"range": {
            "time": {
              "from": "2018-01-16T07:05:00",
              "to": "2018-01-16T10:59:09",
              "include_lower": true,
              "include_upper": true
            }
          }

```

---

<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:** [October 16, 2018, 11:09am UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-default-date-range-in-elasticsearch/148963/2 "2018-10-16T11:09:08Z")

</div>

Closed on October 16, 2018, 11:09am UTC

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