# ES 2.1 range query using a long field as a date returning results that shouldn't

**URL:** <https://discuss.elastic.co/t/es-2-1-range-query-using-a-long-field-as-a-date-returning-results-that-shouldnt/36386>\
**Category:** Elasticsearch\
**Created:** [December 4, 2015, 12:58pm UTC](https://discuss.elastic.co/t/es-2-1-range-query-using-a-long-field-as-a-date-returning-results-that-shouldnt/36386 "2015-12-04T12:58:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbalaguero](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@jbalaguero](https://discuss.elastic.co/u/jbalaguero)\
**Post date:** [December 4, 2015, 12:58pm UTC](https://discuss.elastic.co/t/es-2-1-range-query-using-a-long-field-as-a-date-returning-results-that-shouldnt/36386/1 "2015-12-04T12:58:49Z")

</div>

Hello,

I have an index with a 'creationTime' field of type 'long' and 'not\_analyzed' (represents a date as a long value). I'm indexing hundreds of documents per second. When I perform the next query using the following 'creationTime':

creationTime :: 04-12-2015 13:38:53 == 1449232733933  
creationTime - refresh\_interval (10 seconds) :: 04-12-2015 13:38:43 == **1449232723933**

{ "query" : { "bool" : { "filter" : { "range" : { "creationTime": { "lte": **1449232723933** } } }}} }

I get 12308 documents. When I print the min and max 'creationTime' from these documents, then:  
TOTAL DOCUMENTS = 12308, [min, max] = [04-12-2015 13:37:55, 04-12-2015 13:38:48]

So at least I'm getting a document with creationTime = '04-12-2015 13:38:48', when my query specifies that creationTime \<= '04-12-2015 13:38:43'

If I change my query to:  
{ "query" : { "bool" : { "filter" : { "range" : { "creationTime": { "gte": 1449232723933, "lte": 1449232733933 } } }}} }  
That means creationTime between '04-12-2015 13:38:43' and '04-12-2015 13:38:53'

I get 2305 documents. When I print the min and max 'creationTime' from these documents, then:  
TOTAL DOCUMENTS = 2305, [min, max] = [04-12-2015 13:38:43, 04-12-2015 13:38:53]

So works fine.

Am I doing something wrong? For the first case I tried to add "gte":0, "lte":1449232723933, but the result is the same.

Thanks.

---

<div class="post-metadata">

**Author:** ![jbalaguero](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@jbalaguero](https://discuss.elastic.co/u/jbalaguero)\
**Post date:** [December 4, 2015, 4:36pm UTC](https://discuss.elastic.co/t/es-2-1-range-query-using-a-long-field-as-a-date-returning-results-that-shouldnt/36386/2 "2015-12-04T16:36:57Z")

</div>

Ok, forget it. Not setting the refresh\_interval correctly. Thanks.

---

<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 5, 2017, 11:33pm UTC](https://discuss.elastic.co/t/es-2-1-range-query-using-a-long-field-as-a-date-returning-results-that-shouldnt/36386/3 "2017-07-05T23:33:31Z")

</div>


