Skip to content

Commit

Permalink
Fix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Sep 1, 2020
1 parent 45a839b commit e8dd719
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
},
}
Expand Down
33 changes: 16 additions & 17 deletions x-pack/plugins/apm/typings/elasticsearch/aggregations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ type BucketsPath = string | Record<string, string>;

type SourceOptions = string | string[];

type MetricsAggregationOptions =
type AggregationSourceOptions =
| {
field: string;
missing?: number;
missing?: unknown;
}
| {
script?: Script;
script: Script;
};

interface MetricsAggregationResponsePart {
Expand Down Expand Up @@ -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;
Expand All @@ -69,27 +68,27 @@ export interface AggregationOptionsByType {
max: number;
};
} & ({ calendar_interval: string } | { fixed_interval: string }) &
MetricsAggregationOptions;
AggregationSourceOptions;
histogram: {
interval: number;
min_doc_count?: number;
extended_bounds?: {
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;
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e8dd719

Please sign in to comment.