Files
Ivana Huckova a80fd02f95 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
2023-08-28 16:38:44 +02:00

61 lines
2.1 KiB
TypeScript

import { metricAggregationConfig, pipelineOptions } from './components/QueryEditor/MetricAggregationsEditor/utils';
import {
ElasticsearchQuery,
ExtendedStat,
MetricAggregation,
MovingAverageModelOption,
MetricAggregationType,
DateHistogram,
} from './types';
export const extendedStats: ExtendedStat[] = [
{ label: 'Avg', value: 'avg' },
{ label: 'Min', value: 'min' },
{ label: 'Max', value: 'max' },
{ label: 'Sum', value: 'sum' },
{ label: 'Count', value: 'count' },
{ label: 'Std Dev', value: 'std_deviation' },
{ label: 'Std Dev Upper', value: 'std_deviation_bounds_upper' },
{ label: 'Std Dev Lower', value: 'std_deviation_bounds_lower' },
];
export const movingAvgModelOptions: MovingAverageModelOption[] = [
{ label: 'Simple', value: 'simple' },
{ label: 'Linear', value: 'linear' },
{ label: 'Exponentially Weighted', value: 'ewma' },
{ label: 'Holt Linear', value: 'holt' },
{ label: 'Holt Winters', value: 'holt_winters' },
];
export const highlightTags = {
pre: '@HIGHLIGHT@',
post: '@/HIGHLIGHT@',
};
export const defaultGeoHashPrecisionString = '3';
export function defaultMetricAgg(id = '1'): MetricAggregation {
return { type: 'count', id };
}
export function defaultBucketAgg(id = '1'): DateHistogram {
return { type: 'date_histogram', id, settings: { interval: 'auto' } };
}
export const findMetricById = (metrics: MetricAggregation[], id: MetricAggregation['id']) =>
metrics.find((metric) => metric.id === id);
export function hasMetricOfType(target: ElasticsearchQuery, type: MetricAggregationType): boolean {
return !!target?.metrics?.some((m) => m.type === type);
}
// Even if we have type guards when building a query, we currently have no way of getting this information from the response.
// We should try to find a better (type safe) way of doing the following 2.
export function isPipelineAgg(metricType: MetricAggregationType) {
return metricType in pipelineOptions;
}
export function isPipelineAggWithMultipleBucketPaths(metricType: MetricAggregationType) {
return !!metricAggregationConfig[metricType].supportsMultipleBucketPaths;
}