diff --git a/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs b/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs index 1eb6c6db288..520686c0cde 100644 --- a/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs +++ b/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs @@ -53,15 +53,12 @@ public class DateHistogramAggregation : BucketAggregationBase, IDateHistogramAgg public string Format { - get - { - return !string.IsNullOrEmpty(_format) && - !_format.Contains("date_optional_time") && - ExtendedBounds != null - ? _format + "||date_optional_time" - : _format; - } - set { _format = value; } + get => !string.IsNullOrEmpty(_format) && + !_format.Contains("date_optional_time") && + (ExtendedBounds != null || Missing.HasValue) + ? _format + "||date_optional_time" + : _format; + set => _format = value; } public int? MinimumDocumentCount { get; set; } @@ -94,15 +91,12 @@ public class DateHistogramAggregationDescriptor string IDateHistogramAggregation.Format { - get - { - return !string.IsNullOrEmpty(_format) && - !_format.Contains("date_optional_time") && - Self.ExtendedBounds != null - ? _format + "||date_optional_time" - : _format; - } - set { _format = value; } + get => !string.IsNullOrEmpty(_format) && + !_format.Contains("date_optional_time") && + (Self.ExtendedBounds != null || Self.Missing.HasValue) + ? _format + "||date_optional_time" + : _format; + set => _format = value; } int? IDateHistogramAggregation.MinimumDocumentCount { get; set; } diff --git a/src/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs b/src/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs index 4220f97bf85..1eab8a188e1 100644 --- a/src/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs +++ b/src/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs @@ -15,8 +15,8 @@ namespace Tests.Aggregations.Bucket.DateHistogram * From a functionality perspective, this histogram supports the same features as the normal histogram. * The main difference is that the interval can be specified by date/time expressions. * - * NOTE: When specifying a `format` **and** `extended_bounds`, in order for Elasticsearch to be able to parse - * the serialized `DateTime` of `extended_bounds` correctly, the `date_optional_time` format is included + * NOTE: When specifying a `format` **and** `extended_bounds` or `missing`, in order for Elasticsearch to be able to parse + * the serialized `DateTime` of `extended_bounds` or `missing` correctly, the `date_optional_time` format is included * as part of the `format` value. * * Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram Aggregation].