[v10.1.x] Elasticsearch: Fix respecting of precision in geo hash grid (#73933)
Elasticsearch: Fix respecting of precision in geo hash grid (#73917) * Elasticsearch: Fix ignoring precision when running queries trough backend * Unify default value * Revert "Unify default value" This reverts commitd8e1d207a2. * Update test (cherry picked from commit6742be0c6d) Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
co-authored by
Ivana Huckova
parent
bfab6ccb58
commit
4233541394
@@ -269,7 +269,7 @@ func addFiltersAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg) es.AggBuilder
|
||||
|
||||
func addGeoHashGridAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg) es.AggBuilder {
|
||||
aggBuilder.GeoHashGrid(bucketAgg.ID, bucketAgg.Field, func(a *es.GeoHashGridAggregation, b es.AggBuilder) {
|
||||
a.Precision = bucketAgg.Settings.Get("precision").MustInt(3)
|
||||
a.Precision = stringToIntWithDefaultValue(bucketAgg.Settings.Get("precision").MustString(), 3)
|
||||
aggBuilder = b
|
||||
})
|
||||
|
||||
|
||||
@@ -612,7 +612,7 @@ func TestExecuteElasticsearchDataQuery(t *testing.T) {
|
||||
"id": "3",
|
||||
"type": "geohash_grid",
|
||||
"field": "@location",
|
||||
"settings": { "precision": 3 }
|
||||
"settings": { "precision": "6" }
|
||||
}
|
||||
],
|
||||
"metrics": [{"type": "count", "id": "1" }]
|
||||
@@ -625,6 +625,56 @@ func TestExecuteElasticsearchDataQuery(t *testing.T) {
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "geohash_grid")
|
||||
ghGridAgg := firstLevel.Aggregation.Aggregation.(*es.GeoHashGridAggregation)
|
||||
require.Equal(t, ghGridAgg.Field, "@location")
|
||||
require.Equal(t, ghGridAgg.Precision, 6)
|
||||
})
|
||||
|
||||
t.Run("With geo hash grid agg with invalid int precision", func(t *testing.T) {
|
||||
c := newFakeClient()
|
||||
_, err := executeElasticsearchDataQuery(c, `{
|
||||
"bucketAggs": [
|
||||
{
|
||||
"id": "3",
|
||||
"type": "geohash_grid",
|
||||
"field": "@location",
|
||||
"settings": { "precision": 7 }
|
||||
}
|
||||
],
|
||||
"metrics": [{"type": "count", "id": "1" }]
|
||||
}`, from, to)
|
||||
require.NoError(t, err)
|
||||
sr := c.multisearchRequests[0].Requests[0]
|
||||
|
||||
firstLevel := sr.Aggs[0]
|
||||
require.Equal(t, firstLevel.Key, "3")
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "geohash_grid")
|
||||
ghGridAgg := firstLevel.Aggregation.Aggregation.(*es.GeoHashGridAggregation)
|
||||
require.Equal(t, ghGridAgg.Field, "@location")
|
||||
// It should default to 3
|
||||
require.Equal(t, ghGridAgg.Precision, 3)
|
||||
})
|
||||
|
||||
t.Run("With geo hash grid agg with no precision", func(t *testing.T) {
|
||||
c := newFakeClient()
|
||||
_, err := executeElasticsearchDataQuery(c, `{
|
||||
"bucketAggs": [
|
||||
{
|
||||
"id": "3",
|
||||
"type": "geohash_grid",
|
||||
"field": "@location",
|
||||
"settings": {}
|
||||
}
|
||||
],
|
||||
"metrics": [{"type": "count", "id": "1" }]
|
||||
}`, from, to)
|
||||
require.NoError(t, err)
|
||||
sr := c.multisearchRequests[0].Requests[0]
|
||||
|
||||
firstLevel := sr.Aggs[0]
|
||||
require.Equal(t, firstLevel.Key, "3")
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "geohash_grid")
|
||||
ghGridAgg := firstLevel.Aggregation.Aggregation.(*es.GeoHashGridAggregation)
|
||||
require.Equal(t, ghGridAgg.Field, "@location")
|
||||
// It should default to 3
|
||||
require.Equal(t, ghGridAgg.Precision, 3)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user