# Using epoch timestamp for a date range query?

**URL:** <https://discuss.elastic.co/t/using-epoch-timestamp-for-a-date-range-query/25259>\
**Category:** Elasticsearch\
**Created:** [July 9, 2015, 6:20pm UTC](https://discuss.elastic.co/t/using-epoch-timestamp-for-a-date-range-query/25259 "2015-07-09T18:20:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [July 9, 2015, 6:20pm UTC](https://discuss.elastic.co/t/using-epoch-timestamp-for-a-date-range-query/25259/1 "2015-07-09T18:20:40Z")

</div>

I currently have a few date fields that I store as longs (epoch timestamp in seconds). When searching, I simply provide a range query with another timestamp value. This works perfectly since it's just number comparison. However, when I convert these to a "date" type and try to do the same thing, the search returns documents that are outside of the range. Wondering what I'm doing wrong here. Am I not properly specifying the date format? For reference, here is what I'm using in my mapping:

```
"updated":{  
	"type":"date",
	"numeric_resolution":"seconds"
}

```

When I look at my mapping, I see that Elasticsearch assigned this a format of "dateOptionalTime".

---

<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:** [July 10, 2015, 3:56am UTC](https://discuss.elastic.co/t/using-epoch-timestamp-for-a-date-range-query/25259/2 "2015-07-10T03:56:38Z")

</div>

Are you passing a formatted timestamp or epoch when you do your query with the date mapped field?

---

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [July 10, 2015, 7:33pm UTC](https://discuss.elastic.co/t/using-epoch-timestamp-for-a-date-range-query/25259/3 "2015-07-10T19:33:13Z")

</div>

No, just the long value (for example, 1436556728). I think when I use the string "1436556728" instead of the long value, that solves the issue, but it seems like ES should be able to recognize the non-string value too.

---

<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 6, 2017, 12:02am UTC](https://discuss.elastic.co/t/using-epoch-timestamp-for-a-date-range-query/25259/4 "2017-07-06T00:02:15Z")

</div>


