Skip to content

Commit 26d16dd

Browse files
Wylie Conlondgieselaar
andauthored
[APM] Update aggregations to support script sources (#76429)
* [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>
1 parent e2f283b commit 26d16dd

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

x-pack/plugins/apm/server/projections/typings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type Projection = Omit<APMEventESSearchRequest, 'body'> & {
1515
body: Omit<ESSearchBody, 'aggs'> & {
1616
aggs?: {
1717
[key: string]: {
18-
terms: AggregationOptionsByType['terms'];
18+
terms: AggregationOptionsByType['terms'] & { field: string };
1919
aggs?: AggregationInputMap;
2020
};
2121
};

x-pack/plugins/apm/typings/elasticsearch/aggregations.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ type BucketsPath = string | Record<string, string>;
2323

2424
type SourceOptions = string | string[];
2525

26-
type MetricsAggregationOptions =
26+
type AggregationSourceOptions =
2727
| {
2828
field: string;
29-
missing?: number;
29+
missing?: unknown;
3030
}
3131
| {
32-
script?: Script;
32+
script: Script;
3333
};
3434

3535
interface MetricsAggregationResponsePart {
@@ -56,43 +56,39 @@ type CompositeOptionsSource = Record<
5656

5757
export interface AggregationOptionsByType {
5858
terms: {
59-
field: string;
6059
size?: number;
61-
missing?: string;
6260
order?: SortOptions;
6361
execution_hint?: 'map' | 'global_ordinals';
64-
};
62+
} & AggregationSourceOptions;
6563
date_histogram: {
66-
field: string;
6764
format?: string;
6865
min_doc_count?: number;
6966
extended_bounds?: {
7067
min: number;
7168
max: number;
7269
};
73-
} & ({ calendar_interval: string } | { fixed_interval: string });
70+
} & ({ calendar_interval: string } | { fixed_interval: string }) &
71+
AggregationSourceOptions;
7472
histogram: {
75-
field: string;
7673
interval: number;
7774
min_doc_count?: number;
7875
extended_bounds?: {
7976
min?: number | string;
8077
max?: number | string;
8178
};
82-
};
83-
avg: MetricsAggregationOptions;
84-
max: MetricsAggregationOptions;
85-
min: MetricsAggregationOptions;
86-
sum: MetricsAggregationOptions;
87-
value_count: MetricsAggregationOptions;
88-
cardinality: MetricsAggregationOptions & {
79+
} & AggregationSourceOptions;
80+
avg: AggregationSourceOptions;
81+
max: AggregationSourceOptions;
82+
min: AggregationSourceOptions;
83+
sum: AggregationSourceOptions;
84+
value_count: AggregationSourceOptions;
85+
cardinality: AggregationSourceOptions & {
8986
precision_threshold?: number;
9087
};
9188
percentiles: {
92-
field: string;
9389
percents?: number[];
9490
hdr?: { number_of_significant_value_digits: number };
95-
};
91+
} & AggregationSourceOptions;
9692
extended_stats: {
9793
field: string;
9894
};
@@ -133,25 +129,22 @@ export interface AggregationOptionsByType {
133129
reduce_script: Script;
134130
};
135131
date_range: {
136-
field: string;
137132
format?: string;
138133
ranges: Array<
139134
| { from: string | number }
140135
| { to: string | number }
141136
| { from: string | number; to: string | number }
142137
>;
143138
keyed?: boolean;
144-
};
139+
} & AggregationSourceOptions;
145140
auto_date_histogram: {
146-
field: string;
147141
buckets: number;
148-
};
142+
} & AggregationSourceOptions;
149143
percentile_ranks: {
150-
field: string;
151144
values: string[];
152145
keyed?: boolean;
153146
hdr?: { number_of_significant_value_digits: number };
154-
};
147+
} & AggregationSourceOptions;
155148
}
156149

157150
type AggregationType = keyof AggregationOptionsByType;

0 commit comments

Comments
 (0)