Skip to content

Commit 02147b1

Browse files
russcamMpdreamz
authored andcommitted
Set Format when Missing is specified
Closes #2864
1 parent 8690550 commit 02147b1

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ public class DateHistogramAggregation : BucketAggregationBase, IDateHistogramAgg
5353

5454
public string Format
5555
{
56-
get
57-
{
58-
return !string.IsNullOrEmpty(_format) &&
59-
!_format.Contains("date_optional_time") &&
60-
ExtendedBounds != null
61-
? _format + "||date_optional_time"
62-
: _format;
63-
}
64-
set { _format = value; }
56+
get => !string.IsNullOrEmpty(_format) &&
57+
!_format.Contains("date_optional_time") &&
58+
(ExtendedBounds != null || Missing.HasValue)
59+
? _format + "||date_optional_time"
60+
: _format;
61+
set => _format = value;
6562
}
6663

6764
public int? MinimumDocumentCount { get; set; }
@@ -94,15 +91,12 @@ public class DateHistogramAggregationDescriptor<T>
9491

9592
string IDateHistogramAggregation.Format
9693
{
97-
get
98-
{
99-
return !string.IsNullOrEmpty(_format) &&
100-
!_format.Contains("date_optional_time") &&
101-
Self.ExtendedBounds != null
102-
? _format + "||date_optional_time"
103-
: _format;
104-
}
105-
set { _format = value; }
94+
get => !string.IsNullOrEmpty(_format) &&
95+
!_format.Contains("date_optional_time") &&
96+
(Self.ExtendedBounds != null || Self.Missing.HasValue)
97+
? _format + "||date_optional_time"
98+
: _format;
99+
set => _format = value;
106100
}
107101

108102
int? IDateHistogramAggregation.MinimumDocumentCount { get; set; }

src/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace Tests.Aggregations.Bucket.DateHistogram
1515
* From a functionality perspective, this histogram supports the same features as the normal histogram.
1616
* The main difference is that the interval can be specified by date/time expressions.
1717
*
18-
* NOTE: When specifying a `format` **and** `extended_bounds`, in order for Elasticsearch to be able to parse
19-
* the serialized `DateTime` of `extended_bounds` correctly, the `date_optional_time` format is included
18+
* NOTE: When specifying a `format` **and** `extended_bounds` or `missing`, in order for Elasticsearch to be able to parse
19+
* the serialized `DateTime` of `extended_bounds` or `missing` correctly, the `date_optional_time` format is included
2020
* as part of the `format` value.
2121
*
2222
* Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram Aggregation].

0 commit comments

Comments
 (0)