I am having issues with my Date field while loading it into elasticsearch. Its not coming as proper Date

Viewed 71

Here is my getter setter code :

 public Date getUpdateTime() {
    return UpdateTime;
}

public void setUpdateTime(Date UpdateTime) {
    this.UpdateTime = UpdateTime;
}

Here is my mapping to the elasticsearch :

 event.get(i).setUpdateTime(rs.getDate("UpdateTime").toLocalDate().format(formatter));

Here is my formatter:

String pattern = "MMM dd, yyyy HH:mm:ss.SSSSSSSS";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);

The value coming from the database is in below format , How to get the value in the same format in elasticSearch :

2020-05-18 08:45:13
1 Answers

Send the Date field as string, convert the setters/ getters data type as String, elasticsearch will get it in correct format :

event.get(i).setUpdateTime(rs.getString("UpdateTime"))

You can use Substring if you don't need milliseconds.

Related