# Querying for dates

**URL:** <https://discuss.elastic.co/t/querying-for-dates/8044>\
**Category:** Elasticsearch\
**Created:** [June 11, 2012, 7:11pm UTC](https://discuss.elastic.co/t/querying-for-dates/8044 "2012-06-11T19:11:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Smolyak](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Michael\_Smolyak](https://discuss.elastic.co/u/Michael_Smolyak)\
**Post date:** [June 11, 2012, 7:11pm UTC](https://discuss.elastic.co/t/querying-for-dates/8044/1 "2012-06-11T19:11:01Z")

</div>

Is it possible to query for date values without using a range query or a  
field query. I can successfully run

"query": {  
"bool": {  
"must": [  
{  
"range": {  
"releaseDate": {  
"from": "2011-05-25",  
"to": "2011-05-26",  
"include\_lower": true,  
"include\_upper": false,  
"boost": 2  
}  
}  
}  
]  
}  
}

to get items with release date of '2011-05-25. This query correctly returns  
100 records.

When I run

"query": {  
"bool": {  
"must": {  
"term": {  
"releaseDate": "2011-05-25"  
}  
}  
}  
}

I get no results.

Using

"query": {  
"bool": {  
"must": {  
"query\_string": {  
"query": "2011-05-25"  
}  
}  
}  
}

returns all the records in the data set.

Could someone explain this behavior? How can I run a query similar to the  
last one and only get the records having '2011-05-25' as one of the  
attributes?

Thank you,

Michael

---

<div class="post-metadata">

**Author:** ![Tanguy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy1/32/1749_2.png) [@Tanguy1](https://discuss.elastic.co/u/Tanguy1)\
**Post date:** [June 12, 2012, 7:49am UTC](https://discuss.elastic.co/t/querying-for-dates/8044/2 "2012-06-12T07:49:12Z")

</div>

It seems that your mapping is not correct.Your use case suggests that you  
only want search results for a single day: set index:not\_analyzed and  
type:string for the field "releaseDate" of your mapping, and then use term  
query.

-- Tanguy

Le lundi 11 juin 2012 21:11:01 UTC+2, Michael Smolyak a écrit :

> Is it possible to query for date values without using a range query or a  
> field query. I can successfully run
> 
> "query": {  
> "bool": {  
> "must": [  
> {  
> "range": {  
> "releaseDate": {  
> "from": "2011-05-25",  
> "to": "2011-05-26",  
> "include\_lower": true,  
> "include\_upper": false,  
> "boost": 2  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> to get items with release date of '2011-05-25. This query correctly  
> returns 100 records.
> 
> When I run
> 
> "query": {  
> "bool": {  
> "must": {  
> "term": {  
> "releaseDate": "2011-05-25"  
> }  
> }  
> }  
> }
> 
> I get no results.
> 
> Using
> 
> "query": {  
> "bool": {  
> "must": {  
> "query\_string": {  
> "query": "2011-05-25"  
> }  
> }  
> }  
> }
> 
> returns all the records in the data set.
> 
> Could someone explain this behavior? How can I run a query similar to the  
> last one and only get the records having '2011-05-25' as one of the  
> attributes?
> 
> Thank you,
> 
> Michael

---

<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, 3:24am UTC](https://discuss.elastic.co/t/querying-for-dates/8044/3 "2017-07-06T03:24:52Z")

</div>


