From e8dd7198ee0b9acd6d9cedc351e3f0eacde27981 Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Tue, 1 Sep 2020 18:27:43 -0400 Subject: [PATCH] Fix checks --- .../get_local_filter_query.ts | 14 ++++---- .../apm/typings/elasticsearch/aggregations.ts | 33 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/ui_filters/local_ui_filters/get_local_filter_query.ts b/x-pack/plugins/apm/server/lib/ui_filters/local_ui_filters/get_local_filter_query.ts index cfbd79d37c04..d8d6f9214f74 100644 --- a/x-pack/plugins/apm/server/lib/ui_filters/local_ui_filters/get_local_filter_query.ts +++ b/x-pack/plugins/apm/server/lib/ui_filters/local_ui_filters/get_local_filter_query.ts @@ -23,15 +23,17 @@ export const getLocalFilterQuery = ({ const field = localUIFilters[localUIFilterName]; const filter = getUiFiltersES(omit(uiFilters, field.name)); - const bucketCountAggregation = projection.body.aggs + const projectionSource = + projection.body.aggs && + projection.body.aggs[Object.keys(projection.body.aggs)[0]].terms; + const bucketCountAggregation = projectionSource ? { aggs: { bucket_count: { - cardinality: { - field: - projection.body.aggs[Object.keys(projection.body.aggs)[0]].terms - .field, - }, + cardinality: + 'field' in projectionSource + ? { field: projectionSource.field } + : { script: projectionSource.script }, }, }, } diff --git a/x-pack/plugins/apm/typings/elasticsearch/aggregations.ts b/x-pack/plugins/apm/typings/elasticsearch/aggregations.ts index f4f7e41ad814..402e06241310 100644 --- a/x-pack/plugins/apm/typings/elasticsearch/aggregations.ts +++ b/x-pack/plugins/apm/typings/elasticsearch/aggregations.ts @@ -23,13 +23,13 @@ type BucketsPath = string | Record; type SourceOptions = string | string[]; -type MetricsAggregationOptions = +type AggregationSourceOptions = | { field: string; - missing?: number; + missing?: unknown; } | { - script?: Script; + script: Script; }; interface MetricsAggregationResponsePart { @@ -57,10 +57,9 @@ type CompositeOptionsSource = Record< export interface AggregationOptionsByType { terms: { size?: number; - missing?: string; order?: SortOptions; execution_hint?: 'map' | 'global_ordinals'; - } & MetricsAggregationOptions; + } & AggregationSourceOptions; date_histogram: { format?: string; min_doc_count?: number; @@ -69,7 +68,7 @@ export interface AggregationOptionsByType { max: number; }; } & ({ calendar_interval: string } | { fixed_interval: string }) & - MetricsAggregationOptions; + AggregationSourceOptions; histogram: { interval: number; min_doc_count?: number; @@ -77,19 +76,19 @@ export interface AggregationOptionsByType { min?: number | string; max?: number | string; }; - } & MetricsAggregationOptions; - avg: MetricsAggregationOptions; - max: MetricsAggregationOptions; - min: MetricsAggregationOptions; - sum: MetricsAggregationOptions; - value_count: MetricsAggregationOptions; - cardinality: MetricsAggregationOptions & { + } & AggregationSourceOptions; + avg: AggregationSourceOptions; + max: AggregationSourceOptions; + min: AggregationSourceOptions; + sum: AggregationSourceOptions; + value_count: AggregationSourceOptions; + cardinality: AggregationSourceOptions & { precision_threshold?: number; }; percentiles: { percents?: number[]; hdr?: { number_of_significant_value_digits: number }; - } & MetricsAggregationOptions; + } & AggregationSourceOptions; extended_stats: { field: string; }; @@ -137,15 +136,15 @@ export interface AggregationOptionsByType { | { from: string | number; to: string | number } >; keyed?: boolean; - } & MetricsAggregationOptions; + } & AggregationSourceOptions; auto_date_histogram: { buckets: number; - } & MetricsAggregationOptions; + } & AggregationSourceOptions; percentile_ranks: { values: string[]; keyed?: boolean; hdr?: { number_of_significant_value_digits: number }; - } & MetricsAggregationOptions; + } & AggregationSourceOptions; } type AggregationType = keyof AggregationOptionsByType;