I need to be able to yield the following query using NEST:
GET /blabla/_search
{
"size": 0,
"aggs": {
"groupby": {
"date_histogram": {
"field": "CLOSED_DATE",
"interval": "month",
"format": "yyyyMM",
"min_doc_count": 1,
"time_zone": "UTC",
"missing": "100001"
}
}
}
}
The obstacule to get there is the missing method. It recieves, as a parameter, the replacement for the missing value. Therefore, I came up with this code:
return a => a.DateHistogram(level.ToString(), dh => dh
.Field(param.Item1)
.Interval(param.Item2)
.Format(param.Item3)
.TimeZone(timeZone)
.MinimumDocumentCount(minimumDocumentCount)
.Missing(new DateTime()));
Unfortunately, it doesn;t work as it actually generates this query:
{
"size": 0,
"aggs": {
"groupby": {
"date_histogram": {
"field": "CLOSED_DATE",
"interval": "month",
"format": "yyyyMM",
"min_doc_count": 0,
"time_zone": "UTC",
"missing": "0001-01-01T00:00:00"
}
}
}
}
Apparently, the format is the issue here. How can I work around that?
Cheers!
This looks like a bug in the client; I have added an issue to address this.
In the meantime, you can workaround this by specifying the format as
.Format(param.Item3 + "||date_optional_time")
such that Elasticsearch can deserialize a serialized DateTime
in the format yyyy-MM-ddThh:mm:ss