-
Notifications
You must be signed in to change notification settings - Fork 1.2k
DateHistogram Date Formats #1784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting @RobinRieger 👍 |
This is a outstanding issue in Elasticsearch - see elastic/elasticsearch#9725. To work around it for the time being, when specifying a format on the DateHistogram, include the DateTime startDate = DateTime.UtcNow;
DateTime endDate = DateTime.UtcNow.AddDays(1);
.DateHistogram
("orders",
h => h.Field(fi => fi.OrderDate)
.Interval(DateInterval.Day)
// include the date_optional_time format in order to be able to parse
// the serialized extended bounds
.Format("yyyy-MM-dd'T'HH:mm:ss||date_optional_time")
.MinimumDocumentCount(0)
.ExtendedBounds(startDate, endDate))))) Will update the integration test to include this |
Thanks for the reply. Good find re the outstanding issue. When I reported this I thought the problem was with the serializer in I will try the work around later, but should work and makes sense. |
The problem is that Elasticsearch attempts to parse the date strings passed for To help Elasticsearch out here, passing the format |
I've made a change to append |
Thanks for the explanation. Yeah I tried it with a couple of different queries and date formats. Makes sense and the work around does resolve my issues. 👍 for the change. Way more user friendly. I could have seen myself forgetting to put on |
If I use the
DateHistogram
I keep getting a message that the search failed due to the date format.The search is:
And the message I get is:
failed to parse date field [2016-01-03T00:00:00Z] with format [yyyy-MM-dd'T'HH:mm:ss]
I had a look at the
ExtendedBounds<T>
that is used in theDateHistogramAggregationDescriptor
and I think that it does not take into account the format when serialising. I.e. if I serialise aDateTime
then I do get the format2016-01-03T00:00:00Z
.Should the
DateHistogram
take the format into account when serialising theDateTime
values? Alternatively, how can I send theExtendedBounds
with the date values in the formatyyyy-MM-dd'T'HH:mm:ss
?Note: I tried calling
.ToString("yyyy-MM-dd'T'HH:mm:ss")
but extended bounds required aDateTime
. I also could not find any tests that use theextended bounds
and theformat
at the same time....The text was updated successfully, but these errors were encountered: