elastic/search-ui

Very limited date format support for range facets

ThomasJejkal opened this issue · 2 comments

Describe the bug
Currently, I'm trying to build up a search interface using search-ui together with the Elasticsearch Connector. Some of my facets are supposed to filter by date ranges and are indexed in different formats (year and date_time).
Until today, I was totally confused by the fact, that ranges for year-formatted fields are possible, i.e., via

{
            from: moment().subtract(2, "years").format("yyyy"),
            to: moment().subtract(1, "years").format("yyyy"),
            name: "Last Year"
}

but as soon as I've added the facets for date_time-formatted fields via

 {
            from: moment().subtract(2, "years").format("yyyyMMdd'T'HHmmss.SSSZ").toString(),
            to: moment().subtract(1, "years").format("yyyyMMdd'T'HHmmss.SSSZ").toString(),
            name: "Last Year"
 }

the filter entry was empty and the query failed without further details. Instead, if I tried to apply ISO formatting via

 {
            from: moment().subtract(2, "years").toISOString(),
            to: moment().subtract(1, "years").toISOString(),
            name: "Last Year"
 }

I received an 'official' error telling me failed to parse date field [2024-02-03T10:29:07.383Z] with format [basic_date_time]

I'm not sure why I decided to use 'basic_date_time', but after changing it to 'date_optional_time' everything works fine. However, it was very frustrating to get no hint what happens. Finally, issue #940 helped me to find the cause of the issue at

return typeof dateString === "string" && !isNaN(Date.parse(dateString));
and I'm wondering, if date validation could be less restrictive in here since Elastic seems to be very flexible when it comes to dates and a developer should typically provide the correctly formatted date string.

Instead, it seems to me, that date validation is only used to distinguish between numeric and date ranges so why not accepting all strings as dates and let Elastic complain if some wrong format is applied?

Thanks a lot for consideration.

Hey
Thank you for reporting. I agree that gives a wrong idea about range facet and the format should be controlled by developer and elasticsearch without middleman here
I will add to future improvements

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.