Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.7 BWC layer for Java time formats in mappings does not default timezone to UTC #39067

Closed
droberts195 opened this issue Feb 18, 2019 · 1 comment · Fixed by #39100
Closed
Labels
>bug :Core/Infra/Core Core issues without another label v6.7.0

Comments

@droberts195
Copy link
Contributor

It is documented that timestamps parsed by mappings that do not explicitly specify a timezone are considered to be UTC. In the master branch this behaviour from the days of Joda time seems to have been preserved in the new Java time parsing. However, in the 6.7 BWC layer trying to rely on the default of UTC timestamps parsed by mappings results in an exception.

Steps to reproduce.

First, to show it works as expected in master:

  • git checkout master
  • Start an ES test instance using ./gradlew run
  • Run the following in a different terminal:
curl -H "Content-Type: application/json" -XPUT "localhost:9200/with_tz" -d '{
  "mappings": {
    "properties": {
      "my_time": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ssXX"
      }
    }
  }
}'

curl -H "Content-Type: application/json" -XPOST "localhost:9200/with_tz/_doc/1" -d '{
  "my_time": "2018-02-18 17:47:17Z"
}'

curl -H "Content-Type: application/json" -XPUT "localhost:9200/without_tz" -d '{
  "mappings": {
    "properties": {
      "my_time": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      }
    }
  }
}'

curl -H "Content-Type: application/json" -XPOST "localhost:9200/without_tz/_doc/1" -d '{
  "my_time": "2018-02-18 17:47:17"
}'
  • Note that there are no exceptions and it is possible to index documents both with and without timezones in their timestamps when the Java 8 formats are set in the mappings.

Now to show that things are different in 6.7 when Java 8 timestamp formats are used:

  • git checkout 6.7
  • Start an ES test instance using ./gradlew run
  • Run the following in a different terminal:
curl -H "Content-Type: application/json" -XPUT "localhost:9200/with_tz?include_type_name=false" -d '{
  "mappings": {
    "properties": {
      "my_time": {
        "type": "date",
        "format": "8yyyy-MM-dd HH:mm:ssXX"
      }
    }
  }
}'

curl -H "Content-Type: application/json" -XPOST "localhost:9200/with_tz/_doc/1" -d '{
  "my_time": "2018-02-18 17:47:17Z"
}'

curl -H "Content-Type: application/json" -XPUT "localhost:9200/without_tz?include_type_name=false" -d '{
  "mappings": {
    "properties": {
      "my_time": {
        "type": "date",
        "format": "8yyyy-MM-dd HH:mm:ss"
      }
    }
  }
}'

curl -H "Content-Type: application/json" -XPOST "localhost:9200/without_tz/_doc/1" -d '{
  "my_time": "2018-02-18 17:47:17"
}'
  • The last command returns this error:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [my_time] of type [date] in document with id '1'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [my_time] of type [date] in document with id '1'","caused_by":{"type":"date_time_exception","reason":"Unable to obtain Instant from TemporalAccessor: {},ISO resolved to 2018-02-18T17:47:17 of type java.time.format.Parsed","caused_by":{"type":"unsupported_temporal_type_exception","reason":"Unsupported field: InstantSeconds"}}},"status":400}
  • The ES log contains this error:
[elasticsearch] Caused by: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds
[elasticsearch]         at java.time.format.Parsed.getLong(Parsed.java:203) ~[?:?]
[elasticsearch]         at java.time.Instant.from(Instant.java:373) ~[?:?]
[elasticsearch]         at org.elasticsearch.common.time.DateFormatter.parseMillis(DateFormatter.java:51) ~[elasticsearch-6.7.0-SNAPSHOT.jar:6.7.0-SNAPSHOT]
[elasticsearch]         at org.elasticsearch.index.mapper.DateFieldMapper$DateFieldType.parse(DateFieldMapper.java:246) ~[elasticsearch-6.7.0-SNAPSHOT.jar:6.7.0-SNAPSHOT]
[elasticsearch]         at org.elasticsearch.index.mapper.DateFieldMapper.parseCreateField(DateFieldMapper.java:454) ~[elasticsearch-6.7.0-SNAPSHOT.jar:6.7.0-SNAPSHOT]
[elasticsearch]         at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:297) ~[elasticsearch-6.7.0-SNAPSHOT.jar:6.7.0-SNAPSHOT]
[elasticsearch]         ... 42 more

Unless I'm making a silly mistake I think this is another bug that needs to be fixed before 6.7 GA because otherwise the Java 8 timestamp BWC layer is not robust enough to use for other components of the stack that need to work with many different timestamp formats.

@droberts195 droberts195 added >bug :Core/Infra/Core Core issues without another label v6.7.0 labels Feb 18, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

spinscale added a commit to spinscale/elasticsearch that referenced this issue Feb 19, 2019
The parseMillis method was able to work on formats without timezones by
falling back to UTC. The Java Date Formatter did not support this, as
the calling code was using the `Instant.from` java time API.

This switches over to an internal method which adds UTC as a timezone.

Closes elastic#39067
spinscale added a commit to spinscale/elasticsearch that referenced this issue Feb 19, 2019
The parseMillis method was able to work on formats without timezones by
falling back to UTC. The Java Date Formatter did not support this, as
the calling code was using the `Instant.from` java time API.

This switches over to an internal method which adds UTC as a timezone.

Closes elastic#39067
spinscale added a commit that referenced this issue Feb 19, 2019
The parseMillis method was able to work on formats without timezones by
falling back to UTC. The Date Formatter interface did not support this, as
the calling code was using the `Instant.from` java time API.

This switches over to an internal method which adds UTC as a timezone.

Closes #39067
spinscale added a commit that referenced this issue Feb 19, 2019
The parseMillis method was able to work on formats without timezones by
falling back to UTC. The Date Formatter interface did not support this, as
the calling code was using the `Instant.from` java time API.

This switches over to an internal method which adds UTC as a timezone.

Closes #39067
spinscale added a commit that referenced this issue Feb 19, 2019
The parseMillis method was able to work on formats without timezones by
falling back to UTC. The Date Formatter interface did not support this, as
the calling code was using the `Instant.from` java time API.

This switches over to an internal method which adds UTC as a timezone.

Closes #39067
spinscale added a commit that referenced this issue Feb 19, 2019
The parseMillis method was able to work on formats without timezones by
falling back to UTC. The Java Date Formatter did not support this, as
the calling code was using the `Instant.from` java time API.

This switches over to an internal method which adds UTC as a timezone.

Closes #39067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Core Core issues without another label v6.7.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants