Skip to content

Range queries do not support time_zone with epoch fields #22621

@brandond

Description

@brandond

Elasticsearch version: 5.1.1

Plugins installed: search-guard-ssl

JVM version: openjdk version "1.8.0_111"

OS version: Amazon Linux AMI release 2016.09

Description of the problem including expected versus actual behavior:

The documentation says that dates in ranges can be converted from different time zones using the time_zone parameter. However, specifying a non-UTC time_zone along with the epoch_millis or epoch_second formatter (or not specifying a formatter and simply providing a numeric timestamp) fails because the EpochTimeParser is hardcoded to return failure if the time zone is not UTC:
https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/common/joda/Joda.java#L337

Steps to reproduce:

  1. Execute the following search against a Logstash index:
{
  "query": {
    "range": {
      "@timestamp": {
        "from": "2011-01-13T11:00:00",
        "time_zone": "America/Los_Angeles",
        "format": "strict_date_optional_time"
      }
    }
  }
}
  1. Execute the same search using epoch_millis:
{
  "query": {
    "range": {
      "@timestamp": {
        "from": 1484334000000,
        "time_zone": "America/Los_Angeles",
        "format": "epoch_millis"
      }
    }
  }
}
  1. Execute the same search using epoch_second:
{
  "query": {
    "range": {
      "@timestamp": {
        "from": 1484334000,
        "time_zone": "America/Los_Angeles",
        "format": "epoch_second"
      }
    }
  }
}

Provide logs (if relevant):
The first search (using a datetime string) will work fine. The two searches that use an epoch timestamp fail with a parse exception:

{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "failed to parse date field [1484334000000] with format [epoch_millis]"
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "logstash-2016.12.07",
                "node": "v13nGpFcQrC9EUTjRh8FGA",
                "reason": {
                    "type": "parse_exception",
                    "reason": "failed to parse date field [1484334000000] with format [epoch_millis]",
                    "caused_by": {
                        "type": "illegal_argument_exception",
                        "reason": "Parse failure at index [0] of [1484334000000]"
                    }
                }
            }
        ],
        "caused_by": {
            "type": "parse_exception",
            "reason": "failed to parse date field [1484334000000] with format [epoch_millis]",
            "caused_by": {
                "type": "illegal_argument_exception",
                "reason": "Parse failure at index [0] of [1484334000000]"
            }
        }
    },
    "status": 400
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions