# Query date changes on elasticsearch 2.0

**URL:** <https://discuss.elastic.co/t/query-date-changes-on-elasticsearch-2-0/76562>\
**Category:** Elasticsearch\
**Created:** [February 27, 2017, 1:07am UTC](https://discuss.elastic.co/t/query-date-changes-on-elasticsearch-2-0/76562 "2017-02-27T01:07:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alissonsales](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alissonsales/32/15867_2.png) [@alissonsales](https://discuss.elastic.co/u/alissonsales)\
**Post date:** [February 27, 2017, 1:07am UTC](https://discuss.elastic.co/t/query-date-changes-on-elasticsearch-2-0/76562/1 "2017-02-27T01:07:29Z")

</div>

Hi, I am upgrading a cluster from elasticsearch 1.7 to 2.0 and I have noticed that a specific query is not behaving the same way on the different versions.

I am using the following script to test:

* * *

base\_url="[http://localhost:9201](http://localhost:9201)"

curl "${base\_url}"  
echo ""  
echo "Removing index"  
curl -X DELETE "$base\_url/my\_index"  
echo ""

echo "Creating index and mapping"  
curl -X POST "${base\_url}/my\_index" -d '  
{  
"settings": { "number\_of\_shars": "1", "number\_of\_replicas": "1" },  
"mappings": {  
"user": {  
"properties": {  
"name": { "type": "string" },  
"created\_at": {"type": "date", format: "date\_optional\_time" }  
}  
}  
}  
}  
'  
echo ""  
echo "Add document"  
curl -X PUT "${base\_url}/my\_index/user/1?refresh=true" -d '  
{  
"name": "Jonh Doe",  
"created\_at": "2017-02-05T12:30:45.123Z"  
}  
'  
echo ""  
echo "Query"

## curl -X POST "${base\_url}/my\_index/user/\_search?search\_type=count" -d ' { "query": { "range": { "created\_at": { "gte": "2017-01-01", "lte": "2017-02-05" } } } } ' echo ""

**Results with elasticsearch 2.0.2**

{  
"name" : "Windshear",  
"cluster\_name" : "elasticsearch",  
"version" : {  
"number" : "2.0.2",  
"build\_hash" : "6abf5d8e5b37c2735d8e2f110f9743c453f71e92",  
"build\_timestamp" : "2015-12-16T12:49:58Z",  
"build\_snapshot" : false,  
"lucene\_version" : "5.2.1"  
},  
"tagline" : "You Know, for Search"  
}

Removing index  
{"acknowledged":true}  
Creating index and mapping  
{"acknowledged":true}  
Add document  
{"\_index":"my\_index","\_type":"user","\_id":"1","\_version":1,"\_shards":{"total":2,"successful":1,"failed":0},"created":true}  
Query  
{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":4,"failed":0},"hits":{"total":0,"max\_score":0.0,"hits":[]}}

**Results with elasticsearch 1.7.5**

{  
"status" : 200,  
"name" : "Dr. John Grey",  
"cluster\_name" : "elasticsearch",  
"version" : {  
"number" : "1.7.6",  
"build\_hash" : "c730b59357f8ebc555286794dcd90b3411f517c9",  
"build\_timestamp" : "2016-11-18T15:21:16Z",  
"build\_snapshot" : false,  
"lucene\_version" : "4.10.4"  
},  
"tagline" : "You Know, for Search"  
}

Removing index  
{"acknowledged":true}  
Creating index and mapping  
{"acknowledged":true}  
Add document  
{"\_index":"my\_index","\_type":"user","\_id":"1","\_version":1,"created":true}  
Query  
{"took":4,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.0,"hits":[]}}

* * *

Elasticsearch 1.7 returns 1 and 2.0 returns 0.

I could not find exactly which change is responsible for this on the Breaking Changes document. I've noticed that the default date format has changed, but I expect the query to behave the same when specifying the same format.

Does anybody know why ES 2.0 behaves like this for this query?

Thanks,  
Alisson

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [February 28, 2017, 1:26pm UTC](https://discuss.elastic.co/t/query-date-changes-on-elasticsearch-2-0/76562/2 "2017-02-28T13:26:02Z")

</div>

Hi @alissonsales,

this [bug](https://github.com/elastic/elasticsearch/issues/20579) has been [fixed](https://github.com/elastic/elasticsearch/pull/20582) in [Elasticsearch 2.4.2](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/release-notes-2.4.2.html).

Daniel

---

<div class="post-metadata">

**Author:** ![alissonsales](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alissonsales/32/15867_2.png) [@alissonsales](https://discuss.elastic.co/u/alissonsales)\
**Post date:** [March 6, 2017, 10:46pm UTC](https://discuss.elastic.co/t/query-date-changes-on-elasticsearch-2-0/76562/3 "2017-03-06T22:46:36Z")

</div>

Thanks for the reply @danielmitterdorfer. I ended up opening an issue on Github about this [https://github.com/elastic/elasticsearch/issues/23393](https://github.com/elastic/elasticsearch/issues/23393) and confirmed it was fixed on 2.4.

---

<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:** [April 3, 2017, 10:46pm UTC](https://discuss.elastic.co/t/query-date-changes-on-elasticsearch-2-0/76562/4 "2017-04-03T22:46:36Z")

</div>

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