Skip to content

ES 7 changes which dates date_optional_time can successfully parse #72191

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

Closed
misterbyrne opened this issue Apr 24, 2021 · 3 comments · Fixed by #73034
Closed

ES 7 changes which dates date_optional_time can successfully parse #72191

misterbyrne opened this issue Apr 24, 2021 · 3 comments · Fixed by #73034
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@misterbyrne
Copy link

misterbyrne commented Apr 24, 2021

Elasticsearch version (bin/elasticsearch --version):

Version: 7.12.0, Build: default/tar/78722783c38caa25a70982b5b042074cde5d3b3a/2021-03-18T06:17:15.410153305Z, JVM: 15.0.1

Plugins installed: []

JVM version (java -version):

jdk.app/Contents/Home/bin/java --version
openjdk 15.0.1 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.1+9, mixed mode, sharing)

OS version (uname -a if on a Unix-like system):

Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

Description of the problem including expected versus actual behavior:

The values that the date_optional_time format can successfully parse have changed in ElasticSearch 7.
It seems to be related to dates where the year includes more than 5 digits.

I understand that ES7 includes a migration from Joda time formatters to Java time formatters and there are some expected breaking changes - as documented in the Java time migration guide.

This change in behaviour could be deliberate, but it's not clear from the documentation that this migration affects the date_optional_time built-in format. From the docs:

The switch to java time only impacts custom date and date_nanos formats.

Steps to reproduce:

  1. Create an index with a date field using the date_optional_time format:
curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date",
        "format": "date_optional_time"
      }
    }
  }
}
'
  1. Attempt to create a new document with a value which was valid in ES6.8 (or an index created in ES6.8)
curl -X PUT "localhost:9200/my-index-000001/_create/1?pretty" -H 'Content-Type: application/json' -d'
{
  "date": "123456-01-02T12:34:56"
}
'

Error response:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "failed to parse field [date] of type [date] in document with id '1'. Preview of field's value: '123456-01-02T12:34:56'"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "failed to parse field [date] of type [date] in document with id '1'. Preview of field's value: '123456-01-02T12:34:56'",
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "failed to parse date field [123456-01-02T12:34:56] with format [date_optional_time]",
      "caused_by" : {
        "type" : "date_time_parse_exception",
        "reason" : "Text '123456-01-02T12:34:56' could not be parsed, unparsed text found at index 5"
      }
    }
  },
  "status" : 400
}

Example of this working successfully in ES6.8:

curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "_doc": {
        "properties": {
            "date": {
                "type":   "date",
                "format": "date_optional_time"
            }
        }
    }
  }
}
'
curl -X PUT "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "date": "123456-01-02T12:34:56"
}
'

Response:

{
  "_index" : "my-index-000001",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}
@misterbyrne misterbyrne added >bug needs:triage Requires assignment of a team area label labels Apr 24, 2021
@misterbyrne misterbyrne changed the title ES 7 changes which dates that date_optional_time can successfully parse ES 7 changes which dates date_optional_time can successfully parse Apr 27, 2021
@imotov imotov added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Apr 27, 2021
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Apr 27, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@imotov imotov removed the needs:triage Requires assignment of a team area label label Apr 27, 2021
@cbuescher
Copy link
Member

@pgomulka do you have an opinion on this? I see we accepted up to 9 digits in 6.8 (I see from an error message in 6.8 that "year must be in the range [-292275055,292278994]") but maybe the restriction to 5 digits was introduced in 7x on purpose and this should be a documentation issue? I don't know all the background around these decisions I'm afraid.

@pgomulka
Copy link
Contributor

this might be a bug. As stated in joda 'non strict' date_optional_time had year of length 4-9
the strict_date_optional_time which is a modified ES version had it changed to year of lenght 4-4
I was about to fix this #54260 but I forgot about this PR.
I will try to update the linked PR with the fix for the date_optional_time as well

@pgomulka pgomulka self-assigned this May 10, 2021
pgomulka added a commit that referenced this issue Jun 4, 2021
…l_time (#73034)

We changed the default joda behaviour in strict_date_optional_time to
max 4 digits in a year. Java.time implementation should behave the same way.
At the same time date_optional_time should have 9digits for year part.

closes #52396
closes #72191
pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Jun 4, 2021
…l_time (elastic#73034)

We changed the default joda behaviour in strict_date_optional_time to
max 4 digits in a year. Java.time implementation should behave the same way.
At the same time date_optional_time should have 9digits for year part.

closes elastic#52396
closes elastic#72191
pgomulka added a commit that referenced this issue Jun 7, 2021
…l_time backports(#73034) (#73750)

We changed the default joda behaviour in strict_date_optional_time to
max 4 digits in a year. Java.time implementation should behave the same way.
At the same time date_optional_time should have 9digits for year part.

closes #52396
closes #72191
backports #73034
@javanna javanna added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants