# Fetch results based on Timezone

**URL:** <https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039>\
**Category:** Elasticsearch\
**Created:** [November 8, 2019, 4:16am UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039 "2019-11-08T04:16:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anudeep\_k](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anudeep_k/32/48587_2.png) [@anudeep\_k](https://discuss.elastic.co/u/anudeep_k)\
**Post date:** [November 8, 2019, 4:16am UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039/1 "2019-11-08T04:16:23Z")

</div>

Hi,

I have a inserted a data in elastic search from my timezone(Asia/Kolkata; +05:30) and converted into UTC.please find the below table for reference.  
 ![tz](https://us1.discourse-cdn.com/elastic/original/3X/a/2/a2b9eaa5a7de7eddb0809c8d8ffe10804a9e43fe.png)

Now I am trying to fetch the data by passing my timezone for which i have to view the inserted data in local time(09:30). But the data fetched is still in UTC even when the local timezone is passed.Can some one help me out with this?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 8, 2019, 4:17pm UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039/2 "2019-11-08T16:17:43Z")

</div>

just to fully understand this. you have inserted a document with a date like this

```auto
{
  "timestamp" : "2019-11-08T12:34:56.789+5:30"
}

```

And now you would like to query it as such. Let's take this example

```auto
DELETE test

PUT test/_doc/1?refresh
{
  "timestamp" : "2019-11-08T01:00:00.000+05:30"
}

GET test/_mapping/field/timestamp

# no match, in UTC
GET test/_search
{
  "query": {
    "range": {
      "timestamp": {
        "gte": "2019-11-08"
      }
    }
  }
}

# match, in UTC
GET test/_search
{
  "query": {
    "range": {
      "timestamp": {
        "gte": "2019-11-07"
      }
    }
  }
}

# match in local timezone
GET test/_search
{
  "query": {
    "range": {
      "timestamp": {
        "gte": "2019-11-08T01:00:00.000+05:30"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![anudeep\_k](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anudeep_k/32/48587_2.png) [@anudeep\_k](https://discuss.elastic.co/u/anudeep_k)\
**Post date:** [November 10, 2019, 9:18am UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039/3 "2019-11-10T09:18:08Z")

</div>

Thanks for the time and effort you have put. Say I have inserted a record in UTC,

> "timestamp" : "2019-11-10 08:00:00"  
> "name" : "xxx"

My time zone is Asia/Kolkata (i.e +05:30). Now if I wanted to fetch this record as below .

> "timestamp" : "2019-11-10 13:30:00"  
> "name" : "xxx"

Even if the time zone is passed in the query I am still getting the record in UTC

> "timestamp" : "2019-11-10 08:00:00"  
> "name" : "xxx"

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 11, 2019, 10:10am UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039/4 "2019-11-11T10:10:44Z")

</div>

please share a fully reproducible example

---

<div class="post-metadata">

**Author:** ![anudeep\_k](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anudeep_k/32/48587_2.png) [@anudeep\_k](https://discuss.elastic.co/u/anudeep_k)\
**Post date:** [November 11, 2019, 12:16pm UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039/5 "2019-11-11T12:16:51Z")

</div>

I have inserted a data at given time in milliseconds. I converted my local date time to UTC in milliseconds.

```
POST /test/data/sample
{
"start_time": "1573453784307"
}

```

Now am trying to fetch the data by using the below query

```
GET /test/data/_search
{ 
"size":0,
"query":{ 
    "bool":{ 
        "filter":[ 
            { 
                "range":{ 
                    "start_time":{ 
                        "gte":"2019-11-11 00:00:00.000000+0530"
                    }
                }
            }
        ]
    }
},
"aggregations":{ 
    "timeslice":{ 
        "date_histogram":{ 
            "field":"start_time",
            "format":"yyyy-MM-dd HH:mm:ss",
             "time_zone": "+05:30", 
            "calendar_interval":"hour",
            "extended_bounds":{
                "min":"2019-11-11 00:00:00",
                "max":"2019-11-11 23:59:59"
            },
            "order":{ 
                "_key":"desc"
            }
         }
      }
   }
}

```

I am expecting the doc\_count in the time range as below, since my timezone is +0530

```
{
      "key_as_string" : "2019-11-11 17:00:00",
      "key" : 1573471800000,
      "doc_count" : 1
}

```

But the results I have been getting is (still in UTC range)

```
{
      "key_as_string" : "2019-11-11 11:00:00",
      "key" : 1573450200000,
      "doc_count" : 1
}

```

Can you please help me out with this?

---

<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:** [December 9, 2019, 12:16pm UTC](https://discuss.elastic.co/t/fetch-results-based-on-timezone/207039/6 "2019-12-09T12:16:55Z")

</div>

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