# Incorrect Date Range Query Result

**URL:** <https://discuss.elastic.co/t/incorrect-date-range-query-result/23125>\
**Category:** Elasticsearch\
**Created:** [April 7, 2015, 8:55am UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125 "2015-04-07T08:55:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Crone](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@James\_Crone](https://discuss.elastic.co/u/James_Crone)\
**Post date:** [April 7, 2015, 8:55am UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/1 "2015-04-07T08:55:01Z")

</div>

Hello!

My query is this:

GET \_search  
{  
"query": {  
"bool": {  
"should": [  
{  
"range": {  
"DateTime": {  
"gt": "2015-03-01",  
"lte": "2015-03-09"  
}  
}  
}  
]  
}  
}  
}  
Result is:

{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 11,  
"successful": 11,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "completedata",  
"\_type": "users",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"ID": 1,  
"User\_ID": 1,  
"Name": "Saudia Arabia Bomb",  
"Text": "Saudia Arabia Bomb",  
"Status": "online",  
"DateTime": "2015-03-10T00:00:00.000+05:00",  
"categories\_ID": 1  
}  
}  
]  
}  
}

mapping for date is:

"DateTime" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
}

It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3865ceef-bdc4-4f31-a1ff-e4c574497853%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3865ceef-bdc4-4f31-a1ff-e4c574497853%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jan\_Wolf](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@Jan\_Wolf](https://discuss.elastic.co/u/Jan_Wolf)\
**Post date:** [April 9, 2015, 1:25pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/2 "2015-04-09T13:25:24Z")

</div>

I would try "must" instead of "should" 🙂

Am Dienstag, 7. April 2015 10:55:01 UTC+2 schrieb James Crone:

> Hello!
> 
> My query is this:
> 
> GET \_search  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "range": {  
> "DateTime": {  
> "gt": "2015-03-01",  
> "lte": "2015-03-09"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> Result is:
> 
> {  
> "took": 2,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 11,  
> "successful": 11,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "completedata",  
> "\_type": "users",  
> "\_id": "1",  
> "\_score": 1,  
> "\_source": {  
> "ID": 1,  
> "User\_ID": 1,  
> "Name": "Saudia Arabia Bomb",  
> "Text": "Saudia Arabia Bomb",  
> "Status": "online",  
> "DateTime": "2015-03-10T00:00:00.000+05:00",  
> "categories\_ID": 1  
> }  
> }  
> ]  
> }  
> }
> 
> mapping for date is:
> 
> "DateTime" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> }
> 
> It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3f1ab138-df69-484a-a39f-ccd4579f634a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3f1ab138-df69-484a-a39f-ccd4579f634a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![James\_Crone](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@James\_Crone](https://discuss.elastic.co/u/James_Crone)\
**Post date:** [April 9, 2015, 1:27pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/3 "2015-04-09T13:27:08Z")

</div>

Same problem. ☹

On Thursday, April 9, 2015 at 6:25:25 PM UTC+5, Jan Wolf wrote:

> I would try "must" instead of "should" 🙂
> 
> Am Dienstag, 7. April 2015 10:55:01 UTC+2 schrieb James Crone:
> 
> > Hello!
> > 
> > My query is this:
> > 
> > GET \_search  
> > {  
> > "query": {  
> > "bool": {  
> > "should": [  
> > {  
> > "range": {  
> > "DateTime": {  
> > "gt": "2015-03-01",  
> > "lte": "2015-03-09"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > Result is:
> > 
> > {  
> > "took": 2,  
> > "timed\_out": false,  
> > "\_shards": {  
> > "total": 11,  
> > "successful": 11,  
> > "failed": 0  
> > },  
> > "hits": {  
> > "total": 1,  
> > "max\_score": 1,  
> > "hits": [  
> > {  
> > "\_index": "completedata",  
> > "\_type": "users",  
> > "\_id": "1",  
> > "\_score": 1,  
> > "\_source": {  
> > "ID": 1,  
> > "User\_ID": 1,  
> > "Name": "Saudia Arabia Bomb",  
> > "Text": "Saudia Arabia Bomb",  
> > "Status": "online",  
> > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > "categories\_ID": 1  
> > }  
> > }  
> > ]  
> > }  
> > }
> > 
> > mapping for date is:
> > 
> > "DateTime" : {  
> > "type" : "date",  
> > "format" : "dateOptionalTime"  
> > }
> > 
> > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/65a49d2f-8aa8-4252-84ca-5bb6391bf6b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/65a49d2f-8aa8-4252-84ca-5bb6391bf6b3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jan\_Wolf](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@Jan\_Wolf](https://discuss.elastic.co/u/Jan_Wolf)\
**Post date:** [April 9, 2015, 2:44pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/4 "2015-04-09T14:44:51Z")

</div>

Hmmm strange. Well I if you don't need scoring you should also use filters  
instead of queries. Try this one (works for me):

"query" : {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "\*"  
}  
},  
"filter" : {  
"bool" : {  
"must" : {  
"range" : {  
"DateTime" : {  
"gt" : "....",  
"lte" : "...."  
}  
}  
}  
}  
}  
}  
}

Am Donnerstag, 9. April 2015 15:27:08 UTC+2 schrieb James Crone:

> Same problem. ☹
> 
> On Thursday, April 9, 2015 at 6:25:25 PM UTC+5, Jan Wolf wrote:
> 
> > I would try "must" instead of "should" 🙂
> > 
> > Am Dienstag, 7. April 2015 10:55:01 UTC+2 schrieb James Crone:
> > 
> > > Hello!
> > > 
> > > My query is this:
> > > 
> > > GET \_search  
> > > {  
> > > "query": {  
> > > "bool": {  
> > > "should": [  
> > > {  
> > > "range": {  
> > > "DateTime": {  
> > > "gt": "2015-03-01",  
> > > "lte": "2015-03-09"  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > Result is:
> > > 
> > > {  
> > > "took": 2,  
> > > "timed\_out": false,  
> > > "\_shards": {  
> > > "total": 11,  
> > > "successful": 11,  
> > > "failed": 0  
> > > },  
> > > "hits": {  
> > > "total": 1,  
> > > "max\_score": 1,  
> > > "hits": [  
> > > {  
> > > "\_index": "completedata",  
> > > "\_type": "users",  
> > > "\_id": "1",  
> > > "\_score": 1,  
> > > "\_source": {  
> > > "ID": 1,  
> > > "User\_ID": 1,  
> > > "Name": "Saudia Arabia Bomb",  
> > > "Text": "Saudia Arabia Bomb",  
> > > "Status": "online",  
> > > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > > "categories\_ID": 1  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }
> > > 
> > > mapping for date is:
> > > 
> > > "DateTime" : {  
> > > "type" : "date",  
> > > "format" : "dateOptionalTime"  
> > > }
> > > 
> > > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/58895cc8-f680-44ea-9ded-96af0dae36cf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/58895cc8-f680-44ea-9ded-96af0dae36cf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![James\_Crone](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@James\_Crone](https://discuss.elastic.co/u/James_Crone)\
**Post date:** [April 9, 2015, 2:53pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/5 "2015-04-09T14:53:33Z")

</div>

I have try but same problem. I think this add +1 in date because when i try  
date b/w 2015-03-01 to 2015-03-08 then it return null. and when i try  
2015-03-10 it returns data of 2015-03-10 and 2015-03-11 too. What You say?

On Thursday, April 9, 2015 at 7:44:51 PM UTC+5, Jan Wolf wrote:

> Hmmm strange. Well I if you don't need scoring you should also use filters  
> instead of queries. Try this one (works for me):
> 
> "query" : {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "query" : "\*"  
> }  
> },  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "range" : {  
> "DateTime" : {  
> "gt" : "....",  
> "lte" : "...."  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Am Donnerstag, 9. April 2015 15:27:08 UTC+2 schrieb James Crone:
> 
> > Same problem. ☹
> > 
> > On Thursday, April 9, 2015 at 6:25:25 PM UTC+5, Jan Wolf wrote:
> > 
> > > I would try "must" instead of "should" 🙂
> > > 
> > > Am Dienstag, 7. April 2015 10:55:01 UTC+2 schrieb James Crone:
> > > 
> > > > Hello!
> > > > 
> > > > My query is this:
> > > > 
> > > > GET \_search  
> > > > {  
> > > > "query": {  
> > > > "bool": {  
> > > > "should": [  
> > > > {  
> > > > "range": {  
> > > > "DateTime": {  
> > > > "gt": "2015-03-01",  
> > > > "lte": "2015-03-09"  
> > > > }  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }  
> > > > }  
> > > > Result is:
> > > > 
> > > > {  
> > > > "took": 2,  
> > > > "timed\_out": false,  
> > > > "\_shards": {  
> > > > "total": 11,  
> > > > "successful": 11,  
> > > > "failed": 0  
> > > > },  
> > > > "hits": {  
> > > > "total": 1,  
> > > > "max\_score": 1,  
> > > > "hits": [  
> > > > {  
> > > > "\_index": "completedata",  
> > > > "\_type": "users",  
> > > > "\_id": "1",  
> > > > "\_score": 1,  
> > > > "\_source": {  
> > > > "ID": 1,  
> > > > "User\_ID": 1,  
> > > > "Name": "Saudia Arabia Bomb",  
> > > > "Text": "Saudia Arabia Bomb",  
> > > > "Status": "online",  
> > > > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > > > "categories\_ID": 1  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }
> > > > 
> > > > mapping for date is:
> > > > 
> > > > "DateTime" : {  
> > > > "type" : "date",  
> > > > "format" : "dateOptionalTime"  
> > > > }
> > > > 
> > > > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e9b1cf3f-d864-4142-935c-c35c9cf9a50b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e9b1cf3f-d864-4142-935c-c35c9cf9a50b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jan\_Wolf](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@Jan\_Wolf](https://discuss.elastic.co/u/Jan_Wolf)\
**Post date:** [April 9, 2015, 3:29pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/6 "2015-04-09T15:29:20Z")

</div>

In this case you could just replace "lte" with "lt" if I'm not wrong.  
Otherwise you have to wait for someone other to answer.

Am Donnerstag, 9. April 2015 16:53:33 UTC+2 schrieb James Crone:

> I have try but same problem. I think this add +1 in date because when i  
> try date b/w 2015-03-01 to 2015-03-08 then it return null. and when i try  
> 2015-03-10 it returns data of 2015-03-10 and 2015-03-11 too. What You say?
> 
> On Thursday, April 9, 2015 at 7:44:51 PM UTC+5, Jan Wolf wrote:
> 
> > Hmmm strange. Well I if you don't need scoring you should also use  
> > filters instead of queries. Try this one (works for me):
> > 
> > "query" : {  
> > "filtered" : {  
> > "query" : {  
> > "query\_string" : {  
> > "query" : "\*"  
> > }  
> > },  
> > "filter" : {  
> > "bool" : {  
> > "must" : {  
> > "range" : {  
> > "DateTime" : {  
> > "gt" : "....",  
> > "lte" : "...."  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > Am Donnerstag, 9. April 2015 15:27:08 UTC+2 schrieb James Crone:
> > 
> > > Same problem. ☹
> > > 
> > > On Thursday, April 9, 2015 at 6:25:25 PM UTC+5, Jan Wolf wrote:
> > > 
> > > > I would try "must" instead of "should" 🙂
> > > > 
> > > > Am Dienstag, 7. April 2015 10:55:01 UTC+2 schrieb James Crone:
> > > > 
> > > > > Hello!
> > > > > 
> > > > > My query is this:
> > > > > 
> > > > > GET \_search  
> > > > > {  
> > > > > "query": {  
> > > > > "bool": {  
> > > > > "should": [  
> > > > > {  
> > > > > "range": {  
> > > > > "DateTime": {  
> > > > > "gt": "2015-03-01",  
> > > > > "lte": "2015-03-09"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > ]  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > Result is:
> > > > > 
> > > > > {  
> > > > > "took": 2,  
> > > > > "timed\_out": false,  
> > > > > "\_shards": {  
> > > > > "total": 11,  
> > > > > "successful": 11,  
> > > > > "failed": 0  
> > > > > },  
> > > > > "hits": {  
> > > > > "total": 1,  
> > > > > "max\_score": 1,  
> > > > > "hits": [  
> > > > > {  
> > > > > "\_index": "completedata",  
> > > > > "\_type": "users",  
> > > > > "\_id": "1",  
> > > > > "\_score": 1,  
> > > > > "\_source": {  
> > > > > "ID": 1,  
> > > > > "User\_ID": 1,  
> > > > > "Name": "Saudia Arabia Bomb",  
> > > > > "Text": "Saudia Arabia Bomb",  
> > > > > "Status": "online",  
> > > > > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > > > > "categories\_ID": 1  
> > > > > }  
> > > > > }  
> > > > > ]  
> > > > > }  
> > > > > }
> > > > > 
> > > > > mapping for date is:
> > > > > 
> > > > > "DateTime" : {  
> > > > > "type" : "date",  
> > > > > "format" : "dateOptionalTime"  
> > > > > }
> > > > > 
> > > > > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b2271a25-bc00-4224-8695-c21aac8c8399%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b2271a25-bc00-4224-8695-c21aac8c8399%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![James\_Crone](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@James\_Crone](https://discuss.elastic.co/u/James_Crone)\
**Post date:** [April 9, 2015, 4:23pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/7 "2015-04-09T16:23:11Z")

</div>

Yes I am waiting. Its very important  
On Apr 9, 2015 8:29 PM, "Jan Wolf" [janwolf539@gmail.com](mailto:janwolf539@gmail.com) wrote:

> In this case you could just replace "lte" with "lt" if I'm not wrong.  
> Otherwise you have to wait for someone other to answer.
> 
> Am Donnerstag, 9. April 2015 16:53:33 UTC+2 schrieb James Crone:
> 
> > I have try but same problem. I think this add +1 in date because when i  
> > try date b/w 2015-03-01 to 2015-03-08 then it return null. and when i try  
> > 2015-03-10 it returns data of 2015-03-10 and 2015-03-11 too. What You say?
> > 
> > On Thursday, April 9, 2015 at 7:44:51 PM UTC+5, Jan Wolf wrote:
> > 
> > > Hmmm strange. Well I if you don't need scoring you should also use  
> > > filters instead of queries. Try this one (works for me):
> > > 
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : {  
> > > "query\_string" : {  
> > > "query" : "\*"  
> > > }  
> > > },  
> > > "filter" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "range" : {  
> > > "DateTime" : {  
> > > "gt" : "....",  
> > > "lte" : "...."  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > Am Donnerstag, 9. April 2015 15:27:08 UTC+2 schrieb James Crone:
> > > 
> > > > Same problem. ☹
> > > > 
> > > > On Thursday, April 9, 2015 at 6:25:25 PM UTC+5, Jan Wolf wrote:
> > > > 
> > > > > I would try "must" instead of "should" 🙂
> > > > > 
> > > > > Am Dienstag, 7. April 2015 10:55:01 UTC+2 schrieb James Crone:
> > > > > 
> > > > > > Hello!
> > > > > > 
> > > > > > My query is this:
> > > > > > 
> > > > > > GET \_search  
> > > > > > {  
> > > > > > "query": {  
> > > > > > "bool": {  
> > > > > > "should": [  
> > > > > > {  
> > > > > > "range": {  
> > > > > > "DateTime": {  
> > > > > > "gt": "2015-03-01",  
> > > > > > "lte": "2015-03-09"  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > ]  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > Result is:
> > > > > > 
> > > > > > {  
> > > > > > "took": 2,  
> > > > > > "timed\_out": false,  
> > > > > > "\_shards": {  
> > > > > > "total": 11,  
> > > > > > "successful": 11,  
> > > > > > "failed": 0  
> > > > > > },  
> > > > > > "hits": {  
> > > > > > "total": 1,  
> > > > > > "max\_score": 1,  
> > > > > > "hits": [  
> > > > > > {  
> > > > > > "\_index": "completedata",  
> > > > > > "\_type": "users",  
> > > > > > "\_id": "1",  
> > > > > > "\_score": 1,  
> > > > > > "\_source": {  
> > > > > > "ID": 1,  
> > > > > > "User\_ID": 1,  
> > > > > > "Name": "Saudia Arabia Bomb",  
> > > > > > "Text": "Saudia Arabia Bomb",  
> > > > > > "Status": "online",  
> > > > > > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > > > > > "categories\_ID": 1  
> > > > > > }  
> > > > > > }  
> > > > > > ]  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > mapping for date is:
> > > > > > 
> > > > > > "DateTime" : {  
> > > > > > "type" : "date",  
> > > > > > "format" : "dateOptionalTime"  
> > > > > > }
> > > > > > 
> > > > > > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to a topic in the  
> > > > > > Google Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this topic, visit  
> > > > > > [https://groups.google.com/d/topic/elasticsearch/I38DgJxqS9U/unsubscribe](https://groups.google.com/d/topic/elasticsearch/I38DgJxqS9U/unsubscribe).  
> > > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > > > To view this discussion on the web visit  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/b2271a25-bc00-4224-8695-c21aac8c8399%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b2271a25-bc00-4224-8695-c21aac8c8399%40googlegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/b2271a25-bc00-4224-8695-c21aac8c8399%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b2271a25-bc00-4224-8695-c21aac8c8399%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > .  
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABjqkR8JRe3YGSkxm%2BZVJsCCM0qTeEc8W7E0%2B9E4ftVCVLzjHA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABjqkR8JRe3YGSkxm%2BZVJsCCM0qTeEc8W7E0%2B9E4ftVCVLzjHA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![christian\_5](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@christian\_5](https://discuss.elastic.co/u/christian_5)\
**Post date:** [April 9, 2015, 7:57pm UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/8 "2015-04-09T19:57:02Z")

</div>

Hi,

The timestamp of the event has timezone +05:00 specified, which translates  
to 2015-03-09T19:00:00.000 when converted to UTC. As Elasticsearch uses UTC  
internality default it looks to me that the result is correct as you have  
not specified any timezone in the query.

Christian

On Tuesday, April 7, 2015 at 9:55:01 AM UTC+1, James Crone wrote:

> Hello!
> 
> My query is this:
> 
> GET \_search  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "range": {  
> "DateTime": {  
> "gt": "2015-03-01",  
> "lte": "2015-03-09"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> Result is:
> 
> {  
> "took": 2,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 11,  
> "successful": 11,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "completedata",  
> "\_type": "users",  
> "\_id": "1",  
> "\_score": 1,  
> "\_source": {  
> "ID": 1,  
> "User\_ID": 1,  
> "Name": "Saudia Arabia Bomb",  
> "Text": "Saudia Arabia Bomb",  
> "Status": "online",  
> "DateTime": "2015-03-10T00:00:00.000+05:00",  
> "categories\_ID": 1  
> }  
> }  
> ]  
> }  
> }
> 
> mapping for date is:
> 
> "DateTime" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> }
> 
> It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/26d053f7-6c7a-41ec-a752-9bef6d1bf4e4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/26d053f7-6c7a-41ec-a752-9bef6d1bf4e4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![James\_Crone](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@James\_Crone](https://discuss.elastic.co/u/James_Crone)\
**Post date:** [April 10, 2015, 4:07am UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/9 "2015-04-10T04:07:23Z")

</div>

So, how can I define time zone in my query?  
On Apr 10, 2015 12:57 AM, [christian@elastic.co](mailto:christian@elastic.co) wrote:

> Hi,
> 
> The timestamp of the event has timezone +05:00 specified, which translates  
> to 2015-03-09T19:00:00.000 when converted to UTC. As Elasticsearch uses UTC  
> internality default it looks to me that the result is correct as you have  
> not specified any timezone in the query.
> 
> Christian
> 
> On Tuesday, April 7, 2015 at 9:55:01 AM UTC+1, James Crone wrote:
> 
> > Hello!
> > 
> > My query is this:
> > 
> > GET \_search  
> > {  
> > "query": {  
> > "bool": {  
> > "should": [  
> > {  
> > "range": {  
> > "DateTime": {  
> > "gt": "2015-03-01",  
> > "lte": "2015-03-09"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > Result is:
> > 
> > {  
> > "took": 2,  
> > "timed\_out": false,  
> > "\_shards": {  
> > "total": 11,  
> > "successful": 11,  
> > "failed": 0  
> > },  
> > "hits": {  
> > "total": 1,  
> > "max\_score": 1,  
> > "hits": [  
> > {  
> > "\_index": "completedata",  
> > "\_type": "users",  
> > "\_id": "1",  
> > "\_score": 1,  
> > "\_source": {  
> > "ID": 1,  
> > "User\_ID": 1,  
> > "Name": "Saudia Arabia Bomb",  
> > "Text": "Saudia Arabia Bomb",  
> > "Status": "online",  
> > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > "categories\_ID": 1  
> > }  
> > }  
> > ]  
> > }  
> > }
> > 
> > mapping for date is:
> > 
> > "DateTime" : {  
> > "type" : "date",  
> > "format" : "dateOptionalTime"  
> > }
> > 
> > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/I38DgJxqS9U/unsubscribe](https://groups.google.com/d/topic/elasticsearch/I38DgJxqS9U/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/26d053f7-6c7a-41ec-a752-9bef6d1bf4e4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/26d053f7-6c7a-41ec-a752-9bef6d1bf4e4%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/26d053f7-6c7a-41ec-a752-9bef6d1bf4e4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/26d053f7-6c7a-41ec-a752-9bef6d1bf4e4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABjqkR8eRJbOx4A6\_Or9otCsKpuzuXBFq0TCOtO6nAc3HWR3\_Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABjqkR8eRJbOx4A6_Or9otCsKpuzuXBFq0TCOtO6nAc3HWR3_Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![christian\_5](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@christian\_5](https://discuss.elastic.co/u/christian_5)\
**Post date:** [April 11, 2015, 8:22am UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/10 "2015-04-11T08:22:07Z")

</div>

Hi,

The ability to specify time zone as part of the query was added for the  
1.4.0 release [1]. Assuming you are on 1.4.0 or later, your query should  
look like this:

GET \_search  
{  
"query": {  
"bool": {  
"should": [  
{  
"range": {  
"DateTime": {  
"gt": "2015-03-01",  
"lte": "2015-03-09",  
"time\_zone":"+05:00"  
}  
}  
}  
]  
}  
}  
}

[1] [Add time zone setting for relative date math in range filter/query by dadoonet · Pull Request #7113 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/7113)

Best regards,

Christian

On Tuesday, April 7, 2015 at 9:55:01 AM UTC+1, James Crone wrote:

> Hello!
> 
> My query is this:
> 
> GET \_search  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "range": {  
> "DateTime": {  
> "gt": "2015-03-01",  
> "lte": "2015-03-09"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> Result is:
> 
> {  
> "took": 2,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 11,  
> "successful": 11,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "completedata",  
> "\_type": "users",  
> "\_id": "1",  
> "\_score": 1,  
> "\_source": {  
> "ID": 1,  
> "User\_ID": 1,  
> "Name": "Saudia Arabia Bomb",  
> "Text": "Saudia Arabia Bomb",  
> "Status": "online",  
> "DateTime": "2015-03-10T00:00:00.000+05:00",  
> "categories\_ID": 1  
> }  
> }  
> ]  
> }  
> }
> 
> mapping for date is:
> 
> "DateTime" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> }
> 
> It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/249d02b3-26d5-4288-92ef-b25d9ce9a64b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/249d02b3-26d5-4288-92ef-b25d9ce9a64b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![James\_Crone](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@James\_Crone](https://discuss.elastic.co/u/James_Crone)\
**Post date:** [April 11, 2015, 8:27am UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/11 "2015-04-11T08:27:31Z")

</div>

Thank You Soo much 🙂

On Sat, Apr 11, 2015 at 1:22 PM, [christian@elastic.co](mailto:christian@elastic.co) wrote:

> Hi,
> 
> The ability to specify time zone as part of the query was added for the  
> 1.4.0 release [1]. Assuming you are on 1.4.0 or later, your query should  
> look like this:
> 
> GET \_search  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "range": {  
> "DateTime": {  
> "gt": "2015-03-01",  
> "lte": "2015-03-09",  
> "time\_zone":"+05:00"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> [1] [Add time zone setting for relative date math in range filter/query by dadoonet · Pull Request #7113 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/7113)
> 
> Best regards,
> 
> Christian
> 
> On Tuesday, April 7, 2015 at 9:55:01 AM UTC+1, James Crone wrote:
> 
> > Hello!
> > 
> > My query is this:
> > 
> > GET \_search  
> > {  
> > "query": {  
> > "bool": {  
> > "should": [  
> > {  
> > "range": {  
> > "DateTime": {  
> > "gt": "2015-03-01",  
> > "lte": "2015-03-09"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > Result is:
> > 
> > {  
> > "took": 2,  
> > "timed\_out": false,  
> > "\_shards": {  
> > "total": 11,  
> > "successful": 11,  
> > "failed": 0  
> > },  
> > "hits": {  
> > "total": 1,  
> > "max\_score": 1,  
> > "hits": [  
> > {  
> > "\_index": "completedata",  
> > "\_type": "users",  
> > "\_id": "1",  
> > "\_score": 1,  
> > "\_source": {  
> > "ID": 1,  
> > "User\_ID": 1,  
> > "Name": "Saudia Arabia Bomb",  
> > "Text": "Saudia Arabia Bomb",  
> > "Status": "online",  
> > "DateTime": "2015-03-10T00:00:00.000+05:00",  
> > "categories\_ID": 1  
> > }  
> > }  
> > ]  
> > }  
> > }
> > 
> > mapping for date is:
> > 
> > "DateTime" : {  
> > "type" : "date",  
> > "format" : "dateOptionalTime"  
> > }
> > 
> > It returns me the result of "2015-03-10".How can i get exact result by matching Date? Any Idea?
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/I38DgJxqS9U/unsubscribe](https://groups.google.com/d/topic/elasticsearch/I38DgJxqS9U/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/249d02b3-26d5-4288-92ef-b25d9ce9a64b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/249d02b3-26d5-4288-92ef-b25d9ce9a64b%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/249d02b3-26d5-4288-92ef-b25d9ce9a64b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/249d02b3-26d5-4288-92ef-b25d9ce9a64b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABjqkR8dQAo%2B\_ZE0XhMSW9qBWh8qprYCyY%3DJyNbXKT2zX1Rrhg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABjqkR8dQAo%2B_ZE0XhMSW9qBWh8qprYCyY%3DJyNbXKT2zX1Rrhg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:20am UTC](https://discuss.elastic.co/t/incorrect-date-range-query-result/23125/12 "2017-07-06T00:20:15Z")

</div>


