Elasticsearch: Added support for calendar_interval in ES date histogram queries (#75459)

* Introduce support for calendar intervals in ES date histogram queries

* Add missing undef type check for ES calendar interval query support
This commit is contained in:
NikolayTsvetkov
2023-10-09 12:37:38 +02:00
committed by GitHub
parent 07266aa983
commit ce462e8cd7
5 changed files with 98 additions and 21 deletions
+40
View File
@@ -1669,6 +1669,31 @@ func TestSettingsCasting(t *testing.T) {
assert.NotZero(t, dateHistogramAgg.FixedInterval)
})
t.Run("Uses calendar_interval", func(t *testing.T) {
c := newFakeClient()
_, err := executeElasticsearchDataQuery(c, `{
"bucketAggs": [
{
"type": "date_histogram",
"field": "@timestamp",
"id": "2",
"settings": {
"interval": "1M"
}
}
],
"metrics": [
{ "id": "1", "type": "average", "field": "@value" }
]
}`, from, to)
assert.Nil(t, err)
sr := c.multisearchRequests[0].Requests[0]
dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg)
assert.NotZero(t, dateHistogramAgg.CalendarInterval)
})
})
})
@@ -1755,6 +1780,21 @@ func TestSettingsCasting(t *testing.T) {
dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg)
assert.Equal(t, dateHistogramAgg.FixedInterval, "1d")
})
t.Run("Should use calendar_interval", func(t *testing.T) {
c := newFakeClient()
_, err := executeElasticsearchDataQuery(c, `{
"metrics": [{ "type": "count", "id": "1" }],
"bucketAggs": [
{ "type": "date_histogram", "id": "2", "field": "@time", "settings": { "min_doc_count": "1", "interval": "1w" } }
]
}`, from, to)
assert.Nil(t, err)
sr := c.multisearchRequests[0].Requests[0]
dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg)
assert.Equal(t, dateHistogramAgg.CalendarInterval, "1w")
})
})
}