0

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;

2 Answers 2

1

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));
Sign up to request clarification or add additional context in comments.

Comments

0

Try this custom date format:

@Field(type = FieldType.Date, format = {}, pattern = {"yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.