# How do you store a date that represents the end of time?

**URL:** <https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746>\
**Category:** Elasticsearch\
**Created:** [April 7, 2016, 9:35pm UTC](https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746 "2016-04-07T21:35:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamilnyc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamilnyc/32/8991_2.png) [@jamilnyc](https://discuss.elastic.co/u/jamilnyc)\
**Post date:** [April 7, 2016, 9:35pm UTC](https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746/1 "2016-04-07T21:35:13Z")

</div>

I am indexing a document with an expiration date field that I use as a filter when querying for search results.

A document can either have a date or not, and I'm looking to filter by documents whose expiration is greater than today (i.e., in the future). When there is no expiration date for a document, what should I put as the value for the expiration date in the index? I was thinking something like '9999-12-31' (December 31, 9999) but that is really ugly. There are only gt, gte, lt and lte options on the range filter.

I was thinking of storing null in the field, but am having trouble with OR/AND'ing multiple filters because the expiration date must be in the future OR non-existent AND must match other parameters.

Any ideas?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 7, 2016, 10:05pm UTC](https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746/2 "2016-04-07T22:05:55Z")

</div>

Can I just say that this thread title wins.

---

<div class="post-metadata">

**Author:** ![Joshua\_Rich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshua_rich/32/44953_2.png) [@Joshua\_Rich](https://discuss.elastic.co/u/Joshua_Rich)\
**Post date:** [April 8, 2016, 12:33am UTC](https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746/3 "2016-04-08T00:33:42Z")

</div>

Hi @jamilnyc,

I'd suggest not adding the expiry field at all for these documents and then using a an `exists` query in a `bool` `must_not` clause (ES \>= 2.x) or a `missing` query in older ES versions. Something like:

```auto
{
    "bool" : {
        "must_not" : {
           "exists" : { "field" : "expiry" }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![jamilnyc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamilnyc/32/8991_2.png) [@jamilnyc](https://discuss.elastic.co/u/jamilnyc)\
**Post date:** [July 26, 2016, 7:49pm UTC](https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746/4 "2016-07-26T19:49:39Z")

</div>

Thanks! For simplicity we decided to go with a future date. But I like storing the boolean field idea. I think I'll still give it a try.

---

<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, 10:32pm UTC](https://discuss.elastic.co/t/how-do-you-store-a-date-that-represents-the-end-of-time/46746/5 "2017-07-05T22:32:43Z")

</div>


