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 d8d6f9214f742..cfbd79d37c041 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,17 +23,15 @@ export const getLocalFilterQuery = ({ const field = localUIFilters[localUIFilterName]; const filter = getUiFiltersES(omit(uiFilters, field.name)); - const projectionSource = - projection.body.aggs && - projection.body.aggs[Object.keys(projection.body.aggs)[0]].terms; - const bucketCountAggregation = projectionSource + const bucketCountAggregation = projection.body.aggs ? { aggs: { bucket_count: { - cardinality: - 'field' in projectionSource - ? { field: projectionSource.field } - : { script: projectionSource.script }, + cardinality: { + field: + projection.body.aggs[Object.keys(projection.body.aggs)[0]].terms + .field, + }, }, }, } diff --git a/x-pack/plugins/apm/server/projections/typings.ts b/x-pack/plugins/apm/server/projections/typings.ts index 77a5beaf54605..332ac533e78c6 100644 --- a/x-pack/plugins/apm/server/projections/typings.ts +++ b/x-pack/plugins/apm/server/projections/typings.ts @@ -15,7 +15,7 @@ export type Projection = Omit & { body: Omit & { aggs?: { [key: string]: { - terms: AggregationOptionsByType['terms']; + terms: AggregationOptionsByType['terms'] & { field: string }; aggs?: AggregationInputMap; }; };