Skip to content

Commit

Permalink
Explicitly require field in projection
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Sep 2, 2020
1 parent e8dd719 commit ac1f90b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
}
Expand Down
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

0 comments on commit ac1f90b

Please sign in to comment.