Can I convert a string column type to a timestamp?

I ingested a bunch of documents. They have a property "time" containing strings of the form "2015-01-20 07:52:05.013047". I let Elastic automatically detect the data types and it treated "time" as a string. The schema has it as a keyword. Now that the data is already in there, I want to change this column type date.

What is the easiest way to do this?

Can it be done in Kibana? If not is there a tutorial for doing it in the REST API? (I've gathered you have to reindex, so there are a couple of steps involved here. I'm also not sure if the Reindex API is what I need.)

Hi @wpm

I would recommend a runtime field which returns a Date with a value script like the following:

String datetime = doc['my_string_date_field'].value;
ZonedDateTime zdt = ZonedDateTime.parse(datetime);
emit(zdt.toInstant().toEpochMilli());

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