I'm coding a Java app to insert data in Elasticsearch 7.5.1. When creating the index the property was set like this:
"datetime":{
"type":"date"
}
Now when inserting the date I'm getting this error:
org.elasticsearch.index.mapper.MapperParsingException: failed to parse field [datetime] of type [date] in document with id '195'. Preview of field's value: '2018-11-23 10:38:00'
I'm currently doing it like this:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String v = dateFormat.format(date);
And checking a working index I can see it's formatted like this, example: 2019-10-09T11:11:38.879-04:00
What is the mask to create that format?
SimpleDateFormatandDate. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use for exampleLocalDateTimeandDateTimeFormatter, both from java.time, the modern Java date and time API.