Skip to content

Commit

Permalink
[APM] Update aggregations to support script sources (#76429) (#76667)
Browse files Browse the repository at this point in the history
* [APM] Update aggregations to support script sources

* Fix whitespace

* Fix checks

* Explicitly require field in projection

Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>

Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
  • Loading branch information
Wylie Conlon and dgieselaar committed Sep 3, 2020
1 parent b71b2c1 commit ec95a24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/projections/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Projection = Omit<APMEventESSearchRequest, 'body'> & {
body: Omit<ESSearchBody, 'aggs'> & {
aggs?: {
[key: string]: {
terms: AggregationOptionsByType['terms'];
terms: AggregationOptionsByType['terms'] & { field: string };
aggs?: AggregationInputMap;
};
};
Expand Down
41 changes: 17 additions & 24 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 All @@ -56,43 +56,39 @@ type CompositeOptionsSource = Record<

export interface AggregationOptionsByType {
terms: {
field: string;
size?: number;
missing?: string;
order?: SortOptions;
execution_hint?: 'map' | 'global_ordinals';
};
} & AggregationSourceOptions;
date_histogram: {
field: string;
format?: string;
min_doc_count?: number;
extended_bounds?: {
min: number;
max: number;
};
} & ({ calendar_interval: string } | { fixed_interval: string });
} & ({ calendar_interval: string } | { fixed_interval: string }) &
AggregationSourceOptions;
histogram: {
field: string;
interval: number;
min_doc_count?: number;
extended_bounds?: {
min?: number | string;
max?: number | string;
};
};
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: {
field: string;
percents?: number[];
hdr?: { number_of_significant_value_digits: number };
};
} & AggregationSourceOptions;
extended_stats: {
field: string;
};
Expand Down Expand Up @@ -133,25 +129,22 @@ export interface AggregationOptionsByType {
reduce_script: Script;
};
date_range: {
field: string;
format?: string;
ranges: Array<
| { from: string | number }
| { to: string | number }
| { from: string | number; to: string | number }
>;
keyed?: boolean;
};
} & AggregationSourceOptions;
auto_date_histogram: {
field: string;
buckets: number;
};
} & AggregationSourceOptions;
percentile_ranks: {
field: string;
values: string[];
keyed?: boolean;
hdr?: { number_of_significant_value_digits: number };
};
} & AggregationSourceOptions;
}

type AggregationType = keyof AggregationOptionsByType;
Expand Down

0 comments on commit ec95a24

Please sign in to comment.