Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Update aggregations to support script sources #76429

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

@dgieselaar dgieselaar Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we (should) expect a script option here. I feel like we can solve this differently. Do you mind if I push a small change to your branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free!

? { field: projectionSource.field }
: { script: projectionSource.script },
},
},
}
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