# Timestamp Range Not Working vs. Date Format Range Working

**URL:** <https://discuss.elastic.co/t/timestamp-range-not-working-vs-date-format-range-working/200909>\
**Category:** Elasticsearch\
**Created:** [September 24, 2019, 5:01pm UTC](https://discuss.elastic.co/t/timestamp-range-not-working-vs-date-format-range-working/200909 "2019-09-24T17:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAMichel](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@RAMichel](https://discuss.elastic.co/u/RAMichel)\
**Post date:** [September 24, 2019, 5:01pm UTC](https://discuss.elastic.co/t/timestamp-range-not-working-vs-date-format-range-working/200909/1 "2019-09-24T17:01:31Z")

</div>

Hopefully this makes sense. I have a document with two fields storing the same data, but one is in an epoch\_millis timestamp format, and the other is in a readable format. The mapping for these two fields is:

"latest\_datetime": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss },  
"latest\_timestamp": { "type": "date" },

Where the data inserted via JSON response is an already-formatted date, and a numeric epoch\_millis timestamp. Some example data in those two fields for a document would be:

"latest\_datetime":"2019-09-15 11:19:43",  
"latest\_timestamp":1568560783,

I'm attempting to do a range query (I've also tried a range filter) using ES datemath on the latest\_timestamp field, but the date math always returns zero results. If I were to do the same datemath on the latest\_datetime field, it works as expected. Does ES datemath not work on timestamp representations of dates? Or do I need to explicitly declare the format of the date field as "epoch\_millis" for the datetime math to work?

The relevant part of the query:

{ "range":{ "latest\_timestamp":{ "lte":"now", "gte":"now-60d" } } }

There are a number of different ways to fix this that involve other fields, or doing timestamp math separately, but I'd like to check for certain that this can't be done all in a single query instead. Thank you!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 25, 2019, 12:27pm UTC](https://discuss.elastic.co/t/timestamp-range-not-working-vs-date-format-range-working/200909/2 "2019-09-25T12:27:07Z")

</div>

Note that the date format by default contains `epoch_millis`, which means the date you specified is somewhere near the epoch, and not in 2019...

---

<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 28, 2019, 6:40pm UTC](https://discuss.elastic.co/t/timestamp-range-not-working-vs-date-format-range-working/200909/5 "2019-10-28T18:40:36Z")

</div>

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