Different behavior between POST _add and _update endpoints on documents with epoch_millis dates as strings or int/float

Hello everyone,

According to documentation https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#mapping-date-format ; Elasticsearch parses dates from Strings ... and such, even where your date could be represented as... a int/float, like for a timestamp as the Unix epoch time (eg: 1602022482 -> "1602022482" )

First, why not to parse from int/float as well for date representation like timestamp ? (at least, when the mapping is clear that that field should be a date).

I'm asking the question because I had this problem today:

PUT /test_update_timestamp
{
  "mappings": {
    "properties": {
      "timestamp":    { "type": "date",  "format": "epoch_millis" },  
      "info":  { "type": "text"  }
    }
  }
}

_

POST test_update_timestamp/_doc/
{
  "timestamp": 1601990454497.311,
  "info": "test"
}
# WORKED (SURPRISE!)

POST test_update_timestamp/_doc/
{
  "timestamp": "1601990454497.311",
  "info": "test"
}
# WORKED (expected)

_

POST test_update_timestamp/_update/7dTw_nQBakZdFzO4TJYz
{
  "doc": {
    "timestamp": "1601989445406.2952"
  }
} 
# WORKED (expected)
POST test_update_timestamp/_update/7dTw_nQBakZdFzO4TJYz
{
  "doc": {
    "timestamp":  1601989445406.2952
  }
} 
# DO **NOT** WORKED (surprise / not surprise) -> RequestError(400, 'mapper_parsing_exception', "failed to parse field [timestamp] of type [date] in document with id '69Ts_nQBakZdFzO4LJbf'. Preview of field's value: '1.601990454497311E12'"

_

So, finally, it happens that Elasticsearch can parse dates from int/float representation, without any problem, when creating a new document (surprise!). But when updating a document, Elasticsearch do not to parse dates from int/float representation (surprise but not surprise!) by returning a mapper_parsing_exception.

Why is there a different behavior between the 2 endpoints ? Could it be possible to have the _update endpoint be able to parse dates represented as int/float as well ?

Thanks a lot.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.