# Time zones in query string query not working

**URL:** <https://discuss.elastic.co/t/time-zones-in-query-string-query-not-working/298995>\
**Category:** Elasticsearch\
**Created:** [March 7, 2022, 5:08pm UTC](https://discuss.elastic.co/t/time-zones-in-query-string-query-not-working/298995 "2022-03-07T17:08:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bostjan\_Kovac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bostjan_kovac/32/9671_2.png) [@Bostjan\_Kovac](https://discuss.elastic.co/u/Bostjan_Kovac)\
**Post date:** [March 7, 2022, 5:08pm UTC](https://discuss.elastic.co/t/time-zones-in-query-string-query-not-working/298995/1 "2022-03-07T17:08:36Z")

</div>

I believe that the query string queries are not acknowledging the time\_zone property in the query. I have tested with range query and they are working as expected.

My test index:

```auto
PUT test
{
  "mappings": {
    "dynamic": true
  }
}

PUT test/_doc/1
{
  "testDate": "2022-02-24T15:00:00.000-0000"
}

# working as expected
POST test/_search
{
  "query": {
    "range": {
      "testDate": {
        "gte": "2020-02-24",
        "lte": "2022-02-25T00:00:00",
        "time_zone": "Asia/Tokyo"
      }
    }
  }
}

# NOT working 
POST test/_search
{
  "query": {
    "query_string": {
      "query": "2022-02-25",
      "time_zone": "Asia/Tokyo"
    }
  }
}

```

The last query is not working, although the time "2022-02-24T15:00:00.000-0000" (UTC) is actually the "2022-02-25" date in Asia/Tokyo.

Interestingly:

```auto
POST test/_search
{
  "query": {
    "query_string": {
      "query": "2022-02-24",
      "time_zone": "Asia/Tokyo"
    }
  }
}

# RETURNS
"hits": [
            {
                "_index": "test",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "testDate": "2022-02-24T15:00:00.000-0000"
                }
            }
        ]

```

I investigated with explain and it seems that when time\_zone is used in query string query the date parameters in the query are not converted to the target timezone:

```auto
POST test/_explain/1
{
  "query": {
    "query_string": {
      "query": "2022-02-25",
      "time_zone": "Asia/Tokyo"
    }
  }
}

#RETURNS
{
    "_index": "test",
    "_type": "_doc",
    "_id": "1",
    "matched": false,
    "explanation": {
        "value": 0.0,
        "description": "testDate:[1645747200000 TO 1645833599999] doesn't match id 0",
        "details": []
    }
}

#previous day
POST test/_explain/1
{
  "query": {
    "query_string": {
      "query": "2022-02-24",
      "time_zone": "Asia/Tokyo"
    }
  }
}

#RETURNS
{
    "_index": "test",
    "_type": "_doc",
    "_id": "1",
    "matched": true,
    "explanation": {
        "value": 1.0,
        "description": "testDate:[1645660800000 TO 1645747199999]",
        "details": []
    }
}

```

Those Unix timestamps always resolve to UTC start of day. This makes no sense, since the docu says: " (Optional, string) [Coordinated Universal Time (UTC) offset](https://en.wikipedia.org/wiki/List_of_UTC_time_offsets) or [IANA time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) used to convert `date` values in the query string to UTC." ([Query string query | Elasticsearch Guide [7.7] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-query-string-query.html))

Using different timezone confirms this:

```auto
POST test/_explain/1
{
  "query": {
    "query_string": {
      "query": "2022-02-25",
      "time_zone": "Europe/Vienna"
    }
  }
}

#RETURNS
{
    "_index": "test",
    "_type": "_doc",
    "_id": "1",
    "matched": false,
    "explanation": {
        "value": 0.0,
        "description": "testDate:[1645747200000 TO 1645833599999] doesn't match id 0",
        "details": []
    }
}

```

Is this a defect or am I using it wrong?

---

<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 4, 2022, 5:08pm UTC](https://discuss.elastic.co/t/time-zones-in-query-string-query-not-working/298995/2 "2022-04-04T17:08:52Z")

</div>

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