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;
asked Aug 21, 2020 at 21:21

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));
answered Aug 21, 2020 at 22:39
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'"})
flyingfishcattle
2,2213 gold badges19 silver badges31 bronze badges
answered Jun 16, 2022 at 3:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.