I see Elasticsearch supports multiple date formats for date type fields but could not see the same in Spring Data Elasticsearch field annotation. It seems that Spring Data Elasticsearch only accepts one value for format.
Is it possible to add multiple dates formats as detailed here in the Elasticsearch docs?
Maybe something like:
@Field(type = Date, format = {DateFormat.year_month_day, DateFormat.year_month, hour_minute_second_millis})
private java.util.Date day;
This can be done using the custom date format.
@Field(type = Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
private long date;
Which allows saving documents using epoch date for example, and then you can also leverage the multiple date formats for easy querying:
rangeQuery("date").lt(LocalDate.of(2020, Month.APRIL, 5));