Date Dynamic Mapping


I using ES High rest api to upload json as document, no template is provide.
I want to make an index pattern by date, therefore I added a 'time' field contains time in various formats but it recognized as string in the index pattern window.

I tried some formats:

  • 04-06-2020 12:21:42
  • 04-06-2020T12:21:42
  • 04-06-2020T12:21:42Z
  • 04062020T122143Z
  • Epoch nanoseconds

I also tried to add "Scaled date format" in the advanced settings: ["P1TDF", "YYYY-MM-DD HH:mm:ss"]:

(not really understand the first key, just add format with full time, ss; UPDATE: I also added MM-DD-YYYY HH:mm:ss).

but 'time' field still recognized as string:

(I also haven't date option in the edit page).

How can I recognize this json field as date in dynamic mapping?

Thank you!

P.S. ES 7.6.2

The best practice is to define the mapping before indexing the first document so you force the field as a date.

Why not doing that?

Thank you very much, I thought it's not needed and ES know to recognized date as string...

(Avoid templates to not define the mapping in new environments...)

It can. But I do see that as a bad practice. In my former job, I had a field in which users can enter whatever reference they want to use.
The first user in my app, entered "2012-01-01". The second one entered "foo".
The problem is that the first one was looking like a date so Elasticsearch set to this field the date data type. Obviously the second document was rejected as "foo" can't be a date.

That's why I recommend using explicit mapping.

1 Like

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