Elasticsearch: Fix adding correct min_doc_count to all aggregation types in backend implementation (#59713)

* Elasticsearch: Fix adding correct min_doc_count to all aggregation types in backend implementation

* Update snapshot tests

* Fix linting
This commit is contained in:
Ivana Huckova 2022-12-07 09:47:31 +01:00 committed by GitHub
parent dce7f50d59
commit 13acddd605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 8 deletions

View File

@ -29,6 +29,7 @@
},
"terms": {
"field": "label",
"min_doc_count": 1,
"order": {
"_key": "desc"
},

View File

@ -17,6 +17,7 @@
},
"terms": {
"field": "label",
"min_doc_count": 1,
"order": {
"_key": "desc"
},

View File

@ -227,11 +227,7 @@ func (metricAggregation MetricAgg) generateSettingsForDSL() map[string]interface
}
func (bucketAgg BucketAgg) generateSettingsForDSL() map[string]interface{} {
// TODO: This might also need to be applied to other bucket aggregations and other fields.
switch bucketAgg.Type {
case "date_histogram":
setIntPath(bucketAgg.Settings, "min_doc_count")
}
setIntPath(bucketAgg.Settings, "min_doc_count")
return bucketAgg.Settings.MustMap()
}

View File

@ -310,9 +310,9 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
sr := c.multisearchRequests[0].Requests[0]
firstLevel := sr.Aggs[0]
require.Equal(t, firstLevel.Key, "2")
// FIXME: This is a bug in the current implementation. The min_doc_count is not set.
// termsAgg := firstLevel.Aggregation.Aggregation.(*es.TermsAggregation)
// require.Equal(t, termsAgg.MinDocCount, "1")
termsAgg := firstLevel.Aggregation.Aggregation.(*es.TermsAggregation)
expectedMinDocCount := 1
require.Equal(t, termsAgg.MinDocCount, &expectedMinDocCount)
})
t.Run("With metric percentiles", func(t *testing.T) {