Skip to content

Commit 5cdd30a

Browse files
russcamMpdreamz
authored andcommitted
Set Format when Missing is specified
Closes #2864
1 parent 969d34a commit 5cdd30a

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
@@ -57,15 +57,12 @@ public class DateHistogramAggregation : BucketAggregationBase, IDateHistogramAgg
5757

5858
public string Format
5959
{
60-
get
61-
{
62-
return !string.IsNullOrEmpty(_format) &&
63-
!_format.Contains("date_optional_time") &&
64-
ExtendedBounds != null
65-
? _format + "||date_optional_time"
66-
: _format;
67-
}
68-
set { _format = value; }
60+
get => !string.IsNullOrEmpty(_format) &&
61+
!_format.Contains("date_optional_time") &&
62+
(ExtendedBounds != null || Missing.HasValue)
63+
? _format + "||date_optional_time"
64+
: _format;
65+
set => _format = value;
6966
}
7067

7168
public int? MinimumDocumentCount { get; set; }
@@ -102,15 +99,12 @@ public class DateHistogramAggregationDescriptor<T>
10299

103100
string IDateHistogramAggregation.Format
104101
{
105-
get
106-
{
107-
return !string.IsNullOrEmpty(_format) &&
108-
!_format.Contains("date_optional_time") &&
109-
Self.ExtendedBounds != null
110-
? _format + "||date_optional_time"
111-
: _format;
112-
}
113-
set { _format = value; }
102+
get => !string.IsNullOrEmpty(_format) &&
103+
!_format.Contains("date_optional_time") &&
104+
(Self.ExtendedBounds != null || Self.Missing.HasValue)
105+
? _format + "||date_optional_time"
106+
: _format;
107+
set => _format = value;
114108
}
115109

116110
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)