Time zones in query string query not working

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:

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:

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:

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 or IANA time zone used to convert date values in the query string to UTC." (Query string query | Elasticsearch Guide [7.7] | Elastic)

Using different timezone confirms this:

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?

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