-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Fix false positive date detection with trailing dot #116953
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
Merged
felixbarny
merged 2 commits into
elastic:main
from
felixbarny:fix-date-detection-trailing-dot
Dec 4, 2024
Merged
Fix false positive date detection with trailing dot #116953
felixbarny
merged 2 commits into
elastic:main
from
felixbarny:fix-date-detection-trailing-dot
Dec 4, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
|
Hi @felixbarny, I've created a changelog YAML for you. |
Collaborator
|
Pinging @elastic/es-search-foundations (Team:Search Foundations) |
ldematte
approved these changes
Dec 2, 2024
Contributor
ldematte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good to me, but you might want to have one approval from the search team to ensure this has no unintended side effects.
smalyshev
approved these changes
Dec 3, 2024
This was referenced Dec 4, 2024
Collaborator
felixbarny
added a commit
to felixbarny/elasticsearch
that referenced
this pull request
Dec 4, 2024
felixbarny
added a commit
to felixbarny/elasticsearch
that referenced
this pull request
Dec 4, 2024
elasticsearchmachine
pushed a commit
that referenced
this pull request
Dec 4, 2024
elasticsearchmachine
pushed a commit
that referenced
this pull request
Dec 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
auto-backport
Automatically create backport pull requests when merged
>bug
external-contributor
Pull request authored by a developer outside the Elasticsearch team
:Search Foundations/Mapping
Index mappings, including merging and defining field types
Team:Search Foundations
Meta label for the Search Foundations team in Elasticsearch
v8.17.1
v8.18.0
v9.0.0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Date detection is not supposed to kick in with numeric values:
elasticsearch/server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java
Lines 83 to 100 in 366fa74
The way this is ensured is that string values that can be parsed as a number are not subject to date detection.
However, there's a case where a string can't be parsed as a number but is still considered a date that can be parsed by the default
epoch_millisformatter.That's because the
epoch_millisformat supports parsing numbers with a trailing dot, such as12345., which is equivalent to12345.0or12345. This was made to retain compatibility with Joda time.The issue is that the
MILLISECONDS_FORMATTER2, built to support trailing dots, is implemented as extension ofMILLISECONDS_FORMATTER1, which already supports an optional fractional. The result is thatMILLISECONDS_FORMATTER2supports a fractional and a trailing dot.The bug got introduced in this PR: #36914.
A potential alternative to this approach would be to remove
epoch_millisfrom the default formatters used in date_detection:elasticsearch/server/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java
Lines 61 to 66 in d6cc86a
However, the consequence of this is that it will use a non-default formatter for dynamically detected
datefields (strict_date_optional_timeinstead ofstrict_date_optional_time||epoch_millis). That means the get mapping API will return"date": { "type": "date", "format": "strict_date_optional_time" }for dynamically mapped dates instead of just"date": { "type": "date" }.That's why I've opted for a solution that has a lower chance of unintended side effects.
Fixes #116946