Skip to content

@Field Type Date does not match default format -> strict date formats missing #2779

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
DKlaper opened this issue Nov 22, 2023 · 2 comments · Fixed by #2782
Closed

@Field Type Date does not match default format -> strict date formats missing #2779

DKlaper opened this issue Nov 22, 2023 · 2 comments · Fixed by #2782
Labels
type: enhancement A general enhancement

Comments

@DKlaper
Copy link

DKlaper commented Nov 22, 2023

Short version: I did not manage to map the date format "strict_date_optional_time||epoch_millis" with the provided annotations.

Extended explanation:

  • I have an existing Elasticsearch index with a date field. The date field was created without specifying a format so it has the elasticsearch default of "strict_date_optional_time||epoch_millis" (see here https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html)
  • I then created a @Document-annotated class where I annotate the date field with just @field(type = FieldType.Date).
  • Then I try to put the mapping of the document to the index and get the Exception: "Mapper for XXX conflicts with existing mapper: Cannot update parameter [format] from [strict_date_optional_time||epoch_millis] to [date_optional_time||epoch_millis]"
  • I then also had to find out that I cannot provide the existing format to the annotation @field(type = FieldType.Date, format = ???) because DateFormat does not contain the strict formats.

So I could not find a way to have a strict date format (besides the one with nanos that was added in this issue #2676).

In my opinion annotating @field(type = FieldType.Date) should have the same effect as specifying a date in the mapping without format so should lead implicitely to "strict_date_optional_time||epoch_millis". In addition I think it would make sense for the DateFormat Enum to contain all Elasticsearch supplied values including the strict versions even if from a parsing perspective they are very similar.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2023
@sothawo
Copy link
Collaborator

sothawo commented Nov 26, 2023

Then I try to put the mapping of the document to the index

One cannot update the mapping for an existing field in Elasticsearch.

Besides not being able to change the mapping, do you get errors when writing or reading data with Spring Data Elasticsearch?

@sothawo sothawo added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 26, 2023
@DKlaper
Copy link
Author

DKlaper commented Nov 27, 2023

Then I try to put the mapping of the document to the index

One cannot update the mapping for an existing field in Elasticsearch.

Besides not being able to change the mapping, do you get errors when writing or reading data with Spring Data Elasticsearch?

I do not want to change the mapping! I only execute PutMapping to ensure that the mapping I have in code is up to date with the index.
The only thing that I want is to use spring data elasticsearch with the existing index. However, I do not see a way in which I can annotate my DTO with @field in a way that the mapping generated is the same as the existing mapping.

Maybe I was a bit unclear. Asked differently. I have the following existing property in my mapping:
"dueDate" :{"type":"date" }
which is equivalent to:
"dueDate" :{"type":"date","format":"strict_date_optional_time||epoch_millis" }

How can I annotate my DTO with @field to comply to this mapping?

There is no field type for strict_date_optional_time so the closest I could get was this:
"dueDate" :{"type":"date","format":"date_optional_time||epoch_millis"}
Which is what happens if I don't put the format parameter in the @field annotation

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 27, 2023
sothawo added a commit that referenced this issue Nov 27, 2023
Original Pull Requests #2782
Closes #2779
@sothawo sothawo added this to the 5.3 M1 (2024.0.0) milestone Nov 27, 2023
@sothawo sothawo added type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided labels Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants