mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 06:51:49 +08:00
Elasticsearch: Unify default value for geo hash grid precision across the code to 3 (#73922)
* Unify default value * Use variable to keep default precisions in sync * Use default precision variable * Update precision description * Update defaultPrecisionString and move * Be more specific in naming of variabkle * Revert "Merge remote-tracking branch 'origin' into ivana/es-precision-default-value" This reverts commit 599f236a7717315a43434b88b50aea2fdfb502e3, reversing changes made to 6742be0c6de6b735cf4a0b82143bc628a7622d87. * Revert wrong merge * Revert wrong merge with turned off lefthook
This commit is contained in:
@ -9,6 +9,7 @@ const (
|
|||||||
HighlightPreTagsString = "@HIGHLIGHT@"
|
HighlightPreTagsString = "@HIGHLIGHT@"
|
||||||
HighlightPostTagsString = "@/HIGHLIGHT@"
|
HighlightPostTagsString = "@/HIGHLIGHT@"
|
||||||
HighlightFragmentSize = 2147483647
|
HighlightFragmentSize = 2147483647
|
||||||
|
DefaultGeoHashPrecision = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
// SearchRequestBuilder represents a builder which can build a search request
|
// SearchRequestBuilder represents a builder which can build a search request
|
||||||
@ -452,7 +453,7 @@ func (b *aggBuilderImpl) Filters(key string, fn func(a *FiltersAggregation, b Ag
|
|||||||
func (b *aggBuilderImpl) GeoHashGrid(key, field string, fn func(a *GeoHashGridAggregation, b AggBuilder)) AggBuilder {
|
func (b *aggBuilderImpl) GeoHashGrid(key, field string, fn func(a *GeoHashGridAggregation, b AggBuilder)) AggBuilder {
|
||||||
innerAgg := &GeoHashGridAggregation{
|
innerAgg := &GeoHashGridAggregation{
|
||||||
Field: field,
|
Field: field,
|
||||||
Precision: 5,
|
Precision: DefaultGeoHashPrecision,
|
||||||
}
|
}
|
||||||
aggDef := newAggDef(key, &aggContainer{
|
aggDef := newAggDef(key, &aggContainer{
|
||||||
Type: "geohash_grid",
|
Type: "geohash_grid",
|
||||||
|
@ -269,7 +269,7 @@ func addFiltersAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg) es.AggBuilder
|
|||||||
|
|
||||||
func addGeoHashGridAgg(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) {
|
aggBuilder.GeoHashGrid(bucketAgg.ID, bucketAgg.Field, func(a *es.GeoHashGridAggregation, b es.AggBuilder) {
|
||||||
a.Precision = stringToIntWithDefaultValue(bucketAgg.Settings.Get("precision").MustString(), 3)
|
a.Precision = stringToIntWithDefaultValue(bucketAgg.Settings.Get("precision").MustString(), es.DefaultGeoHashPrecision)
|
||||||
aggBuilder = b
|
aggBuilder = b
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -7,7 +7,13 @@ import {
|
|||||||
isPipelineAggregation,
|
isPipelineAggregation,
|
||||||
isPipelineAggregationWithMultipleBucketPaths,
|
isPipelineAggregationWithMultipleBucketPaths,
|
||||||
} from './components/QueryEditor/MetricAggregationsEditor/aggregations';
|
} from './components/QueryEditor/MetricAggregationsEditor/aggregations';
|
||||||
import { defaultBucketAgg, defaultMetricAgg, findMetricById, highlightTags } from './queryDef';
|
import {
|
||||||
|
defaultBucketAgg,
|
||||||
|
defaultMetricAgg,
|
||||||
|
findMetricById,
|
||||||
|
highlightTags,
|
||||||
|
defaultGeoHashPrecisionString,
|
||||||
|
} from './queryDef';
|
||||||
import {
|
import {
|
||||||
ElasticsearchQuery,
|
ElasticsearchQuery,
|
||||||
TermsQuery,
|
TermsQuery,
|
||||||
@ -231,7 +237,7 @@ export class ElasticQueryBuilder {
|
|||||||
case 'geohash_grid': {
|
case 'geohash_grid': {
|
||||||
esAgg['geohash_grid'] = {
|
esAgg['geohash_grid'] = {
|
||||||
field: aggDef.field,
|
field: aggDef.field,
|
||||||
precision: aggDef.settings?.precision,
|
precision: aggDef.settings?.precision || defaultGeoHashPrecisionString,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { defaultGeoHashPrecisionString } from 'app/plugins/datasource/elasticsearch/queryDef';
|
||||||
|
|
||||||
import { BucketAggregation } from '../../../../types';
|
import { BucketAggregation } from '../../../../types';
|
||||||
import { describeMetric, convertOrderByToMetricId } from '../../../../utils';
|
import { describeMetric, convertOrderByToMetricId } from '../../../../utils';
|
||||||
import { useQuery } from '../../ElasticsearchQueryContext';
|
import { useQuery } from '../../ElasticsearchQueryContext';
|
||||||
@ -61,7 +63,8 @@ export const useDescription = (bucketAgg: BucketAggregation): string => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'geohash_grid': {
|
case 'geohash_grid': {
|
||||||
const precision = Math.max(Math.min(parseInt(bucketAgg.settings?.precision || '5', 10), 12), 1);
|
const precision = parseInt(bucketAgg.settings?.precision || defaultGeoHashPrecisionString, 10);
|
||||||
|
|
||||||
return `Precision: ${precision}`;
|
return `Precision: ${precision}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { InternalTimeZones, SelectableValue } from '@grafana/data';
|
import { InternalTimeZones, SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
|
import { defaultGeoHashPrecisionString } from '../../../queryDef';
|
||||||
import { BucketsConfiguration } from '../../../types';
|
import { BucketsConfiguration } from '../../../types';
|
||||||
|
|
||||||
import { defaultFilter } from './SettingsEditor/FiltersSettingsEditor/utils';
|
import { defaultFilter } from './SettingsEditor/FiltersSettingsEditor/utils';
|
||||||
@ -26,7 +27,7 @@ export const bucketAggregationConfig: BucketsConfiguration = {
|
|||||||
label: 'Geo Hash Grid',
|
label: 'Geo Hash Grid',
|
||||||
requiresField: true,
|
requiresField: true,
|
||||||
defaultSettings: {
|
defaultSettings: {
|
||||||
precision: '3',
|
precision: defaultGeoHashPrecisionString,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
date_histogram: {
|
date_histogram: {
|
||||||
|
@ -32,6 +32,8 @@ export const highlightTags = {
|
|||||||
post: '@/HIGHLIGHT@',
|
post: '@/HIGHLIGHT@',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const defaultGeoHashPrecisionString = '3';
|
||||||
|
|
||||||
export function defaultMetricAgg(id = '1'): MetricAggregation {
|
export function defaultMetricAgg(id = '1'): MetricAggregation {
|
||||||
return { type: 'count', id };
|
return { type: 'count', id };
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user