-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Open
Labels
:Core/Infra/ScriptingScripting abstractions, Painless, and MustacheScripting abstractions, Painless, and Mustache>bugTeam:Core/InfraMeta label for core/infra teamMeta label for core/infra team
Description
Elasticsearch Version
7.17.12
Installed Plugins
No response
Java Version
bundled
OS Version
Linux aa933ae49f18 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Problem Description
When trying to delete a field from an index, which contains an epoch_second date field with a decimal number, an unexpected error occurs on the date field and the deletion doesn't happen.
Seems like in a certain scenario, ES does not recognise decimal numbers in the scientific notation it itself saves the data in.
Steps to Reproduce
PUT /test_ts
{
"mappings": {
"properties": {
"update_datetime" : {
"type" : "date",
"format" : "epoch_second"
},
"is_private" : {
"type" : "boolean"
}
}
}
}
POST test_ts/_doc/1
{
"update_datetime": 1716462600.37034
}
POST test_ts/_update_by_query
{
"script": {
"source": "ctx._source.remove('is_private');",
"lang": "painless"
}
}
Results in:
failed to parse field [update_datetime] of type [date] in document with id '1'. Preview of field's value: '1.71646260037034E9'
Strangely reindexing works fine with no errors:
POST _reindex
{
"source": {
"index": "test_ts"
},
"dest": {
"index": "test_ts_1"
}
}
Logs (if relevant)
No response
Metadata
Metadata
Assignees
Labels
:Core/Infra/ScriptingScripting abstractions, Painless, and MustacheScripting abstractions, Painless, and Mustache>bugTeam:Core/InfraMeta label for core/infra teamMeta label for core/infra team
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
elasticsearchmachine commentedon May 31, 2024
Pinging @elastic/es-core-infra (Team:Core/Infra)
rjernst commentedon May 31, 2024
Can you please add
error_trace=trueto yourtest_ts/_update_by_queryrequest? ie:That should give more details about where the error is actually occurring.
pmishev commentedon Jun 4, 2024
rjernst commentedon Jun 18, 2024
Thanks for the info, I see what is happening.
Your
update_datetimeis passed as a JSON number. When this is parsed in Java (as it is when reindexing), it is placed in a double type. When that double is serialized back out, it uses scientific notation. Yet the epoch_second date format can't handle scientific notation.While understandably confusing, I think fixing this would be difficult. When reindexing we don't know about the mapped types when parsing the source, it's just a json object. It might be possible to rework reindexing to use the original source bytes, but not without a bit of rework.
One workaround that should work is to use a string. So when indexing your original document, try this:
That should retain the orignal formatting when parsed as JSON, and then serialized again as a string to be reindexed.
pmishev commentedon Jun 24, 2024
Thanks for the workaround. So far seems to work after fixing my existing data:
mosche commentedon Jan 10, 2025
The underlying issue is in
XContentHelper.convertToMap, which infers the field type based on the JSON token type. Any number containing a decimal point is converted to a double, possibly causing a precision loss compared to the string representation.doubleonly has 52 bits of mantissa which can only precisely store the number ofnanoseconds until about 6am on April 15th, 1970. Additionally the string representation becomes the scientific notation which the parsers don't know how to deal with.
Related: