# Issue querying for dates

**URL:** https://discuss.elastic.co/t/issue-querying-for-dates/3266
**Category:** Elasticsearch
**Created:** [August 26, 2010, 8:57pm UTC](https://discuss.elastic.co/t/issue-querying-for-dates/3266 "2010-08-26T20:57:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Grant\_Rodgers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grant_rodgers/32/3204_2.png) [@Grant\_Rodgers](https://discuss.elastic.co/u/Grant_Rodgers)
#### Post date: [August 26, 2010, 8:57pm UTC](https://discuss.elastic.co/t/issue-querying-for-dates/3266/1 "2010-08-26T20:57:14Z")

</div>

Hi, I'm having an issue querying for dates, and it's probably me using  
the query dsl wrong, but I can't figure out what the problem is.

This query works:  
{  
"query":{  
"range":{  
"created\_at":{  
"from":"2010-08-26T20:41:52Z",  
"to":"2010-08-26T20:41:52Z"  
}  
}  
}  
}

but this query doesn't:  
{  
"query":{  
"field":{  
"created\_at":"2010-08-26T20:41:52Z"  
}  
}  
}

It throws this exception: [http://gist.github.com/552231](http://gist.github.com/552231)

I'm using 0.9.0 for this test.

Is there something wrong here?

---

<div class="post-metadata">

### Author: ![Grant\_Rodgers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grant_rodgers/32/3204_2.png) [@Grant\_Rodgers](https://discuss.elastic.co/u/Grant_Rodgers)
#### Post date: [August 26, 2010, 9:01pm UTC](https://discuss.elastic.co/t/issue-querying-for-dates/3266/2 "2010-08-26T21:01:01Z")

</div>

Oh also here's the mapping for that field:

```
    "created_at" : {
      "omit_term_freq_and_positions" : true,
      "index_name" : "created_at",
      "index" : "not_analyzed",
      "omit_norms" : true,
      "store" : "no",
      "boost" : 1.0,
      "format" : "dateOptionalTime",
      "precision_step" : 4,
      "term_vector" : "no",
      "type" : "date"
    },

```

On Aug 26, 1:57 pm, Grant Rodgers [gra...@gmail.com](mailto:gra...@gmail.com) wrote:

> Hi, I'm having an issue querying for dates, and it's probably me using  
> the query dsl wrong, but I can't figure out what the problem is.
> 
> This query works:  
> {  
> "query":{  
> "range":{  
> "created\_at":{  
> "from":"2010-08-26T20:41:52Z",  
> "to":"2010-08-26T20:41:52Z"  
> }  
> }  
> }
> 
> }
> 
> but this query doesn't:  
> {  
> "query":{  
> "field":{  
> "created\_at":"2010-08-26T20:41:52Z"  
> }  
> }
> 
> }
> 
> It throws this exception:[gist:552231 · GitHub](http://gist.github.com/552231)
> 
> I'm using 0.9.0 for this test.
> 
> Is there something wrong here?

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [August 26, 2010, 9:38pm UTC](https://discuss.elastic.co/t/issue-querying-for-dates/3266/3 "2010-08-26T21:38:15Z")

</div>

> but this query doesn't:  
> {  
> "query":{  
> "field":{  
> "created\_at":"2010-08-26T20:41:52Z"  
> }  
> }  
> }

A 'field' query is for query strings. Use a term query instead:

{  
"query":{  
"field":{  
"term":"2010-08-26T20:41:52Z"  
}  
}  
}

clint

---

<div class="post-metadata">

### Author: ![Grant\_Rodgers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grant_rodgers/32/3204_2.png) [@Grant\_Rodgers](https://discuss.elastic.co/u/Grant_Rodgers)
#### Post date: [August 26, 2010, 10:12pm UTC](https://discuss.elastic.co/t/issue-querying-for-dates/3266/4 "2010-08-26T22:12:07Z")

</div>

Ah, it makes sense now that I know field queries are query strings,  
because colons are reserved in query strings. Escaping the colons  
fixes the query:

{  
"query":{  
"field":{  
"created\_at":"2010-08-26T20\:41\:52Z"  
}  
}  
}

(double backslashes so the json parser doesn't throw an error)

Thanks!

On Aug 26, 2:38 pm, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> > but this query doesn't:  
> > {  
> > "query":{  
> > "field":{  
> > "created\_at":"2010-08-26T20:41:52Z"  
> > }  
> > }  
> > }
> 
> A 'field' query is for query strings. Use a term query instead:
> 
> {  
> "query":{  
> "field":{  
> "term":"2010-08-26T20:41:52Z"  
> }  
> }
> 
> }
> 
> clint

---

<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, 4:20am UTC](https://discuss.elastic.co/t/issue-querying-for-dates/3266/5 "2017-07-06T04:20:17Z")

</div>


