# Clarification on using date ranges for URI searches

**URL:** https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815
**Category:** Elasticsearch
**Created:** [July 16, 2019, 6:43pm UTC](https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815 "2019-07-16T18:43:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jason\_Baumgartner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_baumgartner/32/92716_2.png) [@Jason\_Baumgartner](https://discuss.elastic.co/u/Jason_Baumgartner)
#### Post date: [July 16, 2019, 6:43pm UTC](https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815/1 "2019-07-16T18:43:56Z")

</div>

I am currently experimenting with using a Raspberry Pi 4 to ingest Reddit data in real-time. It is working very well, but I'm having a hard time finding concise documentation on how to use date ranges for a URI search.

For example, to set the range for the last hour I can do this:

[http://pi4.pushshift.io/rc/\_search/?pretty&sort=created\_utc:desc&size=250&q=created\_utc:[now-1h%20TO%20now]](http://pi4.pushshift.io/rc/_search/?pretty&sort=created_utc:desc&size=250&q=created_utc:%5Bnow-1h%20TO%20now%5D)

This works as expected. However, if I try to use actual dates, I don't get back any data. For example:

[http://pi4.pushshift.io/rc/\_search/?pretty&sort=created\_utc:desc&size=250&q=created\_utc:["2019-01-01"%20TO%20"2020-01-01"]](http://pi4.pushshift.io/rc/_search/?pretty&sort=created_utc:desc&size=250&q=created_utc:%5B%222019-01-01%22%20TO%20%222020-01-01%22%5D)

I also tried including the time portion but that returned an empty set as well:

[http://pi4.pushshift.io/rc/\_search/?pretty&sort=created\_utc:desc&size=250&q=created\_utc:["2019-01-01T00:00:00"%20TO%20"2020-01-01T00:00:00"]](http://pi4.pushshift.io/rc/_search/?pretty&sort=created_utc:desc&size=250&q=created_utc:%5B%222019-01-01T00:00:00%22%20TO%20%222020-01-01T00:00:00%22%5D)

I would expect this to return results since I'm searching for a range for the entire year, but no documents are returned. What is the correct syntax when searching exact dates or datetime values?

The mapping for the created\_utc field is as follows:

> "created\_utc": {  
> "type": "date",  
> "format": "epoch\_second"  
> }

Also, this is the entire mapping for the index: [http://pi4.pushshift.io/\_mapping?pretty](http://pi4.pushshift.io/_mapping?pretty)

These are the indices: [http://pi4.pushshift.io/\_cat/indices](http://pi4.pushshift.io/_cat/indices)

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 16, 2019, 7:41pm UTC](https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815/2 "2019-07-16T19:41:34Z")

</div>

My guess is that because you defined `"format":"epoch_second"` in your mapping, elasticsearch can only parse dates which are `epoch_second` and not any other text.

May be you should try with an array like:

```auto
"format": ["OTHER_FORMAT", "epoch_second"]

```

That's a guess. I did not try to reproduce yet.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 16, 2019, 7:46pm UTC](https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815/3 "2019-07-16T19:46:03Z")

</div>

So this works:

```auto
DELETE test
PUT test
{
  "mappings": {
    "properties": {
      "date": {
        "type": "date",
        "format": "dd/MM/yyyy||epoch_second"
      }
    }
  }
}
PUT test/_doc/1
{
  "date": "26/12/1971"
}
GET test/_search?q=date:["01/12/1971" TO "01/01/1972"]

```

Note that you can't use `"epoch_second||dd/MM/yyyy"`. Only the first format is applied.

---

<div class="post-metadata">

### Author: ![Jason\_Baumgartner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_baumgartner/32/92716_2.png) [@Jason\_Baumgartner](https://discuss.elastic.co/u/Jason_Baumgartner)
#### Post date: [July 16, 2019, 9:20pm UTC](https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815/4 "2019-07-16T21:20:33Z")

</div>

Thank you David! I appreciate the reply and really enjoy your responses in this forum. You do a great job helping others with their questions. From one developer to another, you do a great service to the community.

My thought process in this example was that Elasticsearch would be able to internally translate the datetime to the appropriate epoch value.

---

<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: [August 13, 2019, 9:20pm UTC](https://discuss.elastic.co/t/clarification-on-using-date-ranges-for-uri-searches/190815/5 "2019-08-13T21:20:42Z")

</div>

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