diff --git a/quesma/model/bucket_aggregations/date_histogram.go b/quesma/model/bucket_aggregations/date_histogram.go index e96902658..db716060f 100644 --- a/quesma/model/bucket_aggregations/date_histogram.go +++ b/quesma/model/bucket_aggregations/date_histogram.go @@ -216,10 +216,14 @@ func (query *DateHistogram) NewRowsTransformer() model.QueryRowsTransformer { differenceBetweenTwoNextKeys := int64(1) if query.intervalType == DateHistogramCalendarInterval { duration, err := kibana.ParseInterval(query.interval) - if err != nil { + if err == nil { + differenceBetweenTwoNextKeys = duration.Milliseconds() + } else { + // Let's do 1000 years here (arbitrary huge number), log an error, and continue normally. + // The transformer just won't add any rows. logger.ErrorWithCtx(query.ctx).Err(err) + differenceBetweenTwoNextKeys = (time.Hour * 24 * 365 * 1000).Milliseconds() } - differenceBetweenTwoNextKeys = duration.Milliseconds() } return &DateHistogramRowsTransformer{minDocCount: query.minDocCount, differenceBetweenTwoNextKeys: differenceBetweenTwoNextKeys} } diff --git a/quesma/testdata/dates.go b/quesma/testdata/dates.go index 631ca8645..c7656ec6c 100644 --- a/quesma/testdata/dates.go +++ b/quesma/testdata/dates.go @@ -9,30 +9,30 @@ var AggregationTestsWithDates = []AggregationTestCase{ TestName: "simple max/min aggregation as 2 siblings", QueryRequestJson: ` { - "aggs": { - "sampler": { - "aggs": { - "eventRate": { - "date_histogram": { - "extended_bounds": { - "max": 1727859403270, - "min": 1727858503270 - }, - "field": "order_date", - "calendar_interval": "1w", - "min_doc_count": 0 - } - } - }, - "random_sampler": { - "probability": 0.000001, - "seed": "1292529172" - } - } - }, - "size": 0, - "track_total_hits": false -}`, + "aggs": { + "sampler": { + "aggs": { + "eventRate": { + "date_histogram": { + "extended_bounds": { + "max": 1727859403270, + "min": 1727858503270 + }, + "field": "order_date", + "calendar_interval": "1w", + "min_doc_count": 0 + } + } + }, + "random_sampler": { + "probability": 0.000001, + "seed": "1292529172" + } + } + }, + "size": 0, + "track_total_hits": false + }`, ExpectedResponse: ` { "completion_time_in_millis": 1707486436398,