# Timestamp range not querying properly

**URL:** <https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782>\
**Category:** Elasticsearch\
**Created:** [June 21, 2019, 12:33am UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782 "2019-06-21T00:33:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryh](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@ryh](https://discuss.elastic.co/u/ryh)\
**Post date:** [June 21, 2019, 12:33am UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/1 "2019-06-21T00:33:47Z")

</div>

Hi,

I'm using elasticsearch 7.X and I'm having difficulties querying a time range.  
My code

```auto
res = es.search(index='*', body={
  'query': {
    'range': {
      'app_timestamp':{
      	'gte': '2019-06-20T12:00:00',
      	'lte': '2019-06-20T14:00:00',
        'time_zone': '+07:00'
      }
     }
  }
})

```

Some of the data

```auto
{
  "_index": "some_index",
  "_type": "SOME_TYPE",
  "_id": "amG7dmsBLEIGz_GafLkN",
  "_version": 1,
  "_score": 0,
  "_source": {
    "raw_message": "2019-06-20 13:56:20,144 DETAILS",
    "app_timestamp": "2019-06-20 13:56:20,144",
},
{
  "_index": "some_index",
  "_type": "SOME_TYPE",
  "_id": "h6WsdmsBa0Tg62_0xLj1",
  "_version": 1,
  "_score": 0,
  "_source": {
    "raw_message": "2019-06-20 13:56:02,347 GIVE ME DETAILS",
    "app_timestamp": "2019-06-20 13:56:02,347"
  }
},
{
  "_index": "some_index",
  "_type": "SOME_TYPE",
  "_id": "h6WsdmsBa0Tg62_0xLj1",
  "_version": 1,
  "_score": 0,
  "_source": {
    "raw_message": "2019-06-20 13:56:02,247 GIVE ME DETAILS",
    "app_timestamp": "2019-06-20 13:56:02,247"
  }
}

```

The result is the following:

```auto
{'_shards': {'failed': 0, 'skipped': 0, 'successful': 4, 'total': 4},
 'hits': {'hits': [],
          'max_score': None,
          'total': {'relation': 'eq', 'value': 0}},
 'timed_out': False,
 'took': 0}

```

I've tried changing my index to 'some\_index' also.

Thanks in advance,  
Ry

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [June 21, 2019, 1:57am UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/2 "2019-06-21T01:57:27Z")

</div>

What's your time zone? You coded UTC time with a default zero timezone in your query clause.

---

<div class="post-metadata">

**Author:** ![ryh](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@ryh](https://discuss.elastic.co/u/ryh)\
**Post date:** [June 21, 2019, 3:58pm UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/3 "2019-06-21T15:58:07Z")

</div>

I'm on PTC. I modified my query and data but I'm still not getting any results back.

---

<div class="post-metadata">

**Author:** ![ryh](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@ryh](https://discuss.elastic.co/u/ryh)\
**Post date:** [June 21, 2019, 4:34pm UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/4 "2019-06-21T16:34:36Z")

</div>

Here's a screenshot on what is happening.

 ![Screenshot%20from%202019-06-21%2009-27-02](https://us1.discourse-cdn.com/elastic/original/3X/5/2/52b798eb59c7ccdca578b0207941af16da43f671.png)

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [June 22, 2019, 6:43am UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/5 "2019-06-22T06:43:21Z")

</div>

What's the mapping of documents? Why don't you use date format same as your raw data in query script?

---

<div class="post-metadata">

**Author:** ![ryh](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@ryh](https://discuss.elastic.co/u/ryh)\
**Post date:** [June 24, 2019, 3:59pm UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/6 "2019-06-24T15:59:10Z")

</div>

It works now. I'm forced to use a mapping on my indexes.

Thanks for the reply!  
Ry

---

<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 22, 2019, 3:59pm UTC](https://discuss.elastic.co/t/timestamp-range-not-querying-properly/186782/7 "2019-07-22T15:59:15Z")

</div>

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