query_def.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { DateHistogram } from './components/QueryEditor/BucketAggregationsEditor/aggregations';
  2. import {
  3. ExtendedStat,
  4. MetricAggregation,
  5. MovingAverageModelOption,
  6. MetricAggregationType,
  7. } from './components/QueryEditor/MetricAggregationsEditor/aggregations';
  8. import { metricAggregationConfig, pipelineOptions } from './components/QueryEditor/MetricAggregationsEditor/utils';
  9. import { ElasticsearchQuery } from './types';
  10. export const extendedStats: ExtendedStat[] = [
  11. { label: 'Avg', value: 'avg' },
  12. { label: 'Min', value: 'min' },
  13. { label: 'Max', value: 'max' },
  14. { label: 'Sum', value: 'sum' },
  15. { label: 'Count', value: 'count' },
  16. { label: 'Std Dev', value: 'std_deviation' },
  17. { label: 'Std Dev Upper', value: 'std_deviation_bounds_upper' },
  18. { label: 'Std Dev Lower', value: 'std_deviation_bounds_lower' },
  19. ];
  20. export const movingAvgModelOptions: MovingAverageModelOption[] = [
  21. { label: 'Simple', value: 'simple' },
  22. { label: 'Linear', value: 'linear' },
  23. { label: 'Exponentially Weighted', value: 'ewma' },
  24. { label: 'Holt Linear', value: 'holt' },
  25. { label: 'Holt Winters', value: 'holt_winters' },
  26. ];
  27. export const highlightTags = {
  28. pre: '@HIGHLIGHT@',
  29. post: '@/HIGHLIGHT@',
  30. };
  31. export function defaultMetricAgg(id = '1'): MetricAggregation {
  32. return { type: 'count', id };
  33. }
  34. export function defaultBucketAgg(id = '1'): DateHistogram {
  35. return { type: 'date_histogram', id, settings: { interval: 'auto' } };
  36. }
  37. export const findMetricById = (metrics: MetricAggregation[], id: MetricAggregation['id']) =>
  38. metrics.find((metric) => metric.id === id);
  39. export function hasMetricOfType(target: ElasticsearchQuery, type: MetricAggregationType): boolean {
  40. return !!target?.metrics?.some((m) => m.type === type);
  41. }
  42. // Even if we have type guards when building a query, we currently have no way of getting this information from the response.
  43. // We should try to find a better (type safe) way of doing the following 2.
  44. export function isPipelineAgg(metricType: MetricAggregationType) {
  45. return metricType in pipelineOptions;
  46. }
  47. export function isPipelineAggWithMultipleBucketPaths(metricType: MetricAggregationType) {
  48. return !!metricAggregationConfig[metricType].supportsMultipleBucketPaths;
  49. }