From 3efb0f045c037532df076e30b673603bbb8e274f Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Mon, 27 Jan 2020 15:22:53 +0000 Subject: [PATCH] [ML] Fixing "aggs" use in datafeeds (#56002) * [ML] Fixing "aggs" use in datafeeds * removing use of Record --- .../jobs/new_job/common/job_creator/configs/datafeed.ts | 4 +++- .../jobs/new_job/common/job_creator/job_creator.ts | 6 ++++-- .../jobs/new_job/common/job_creator/util/general.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/configs/datafeed.ts b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/configs/datafeed.ts index 6c7493c5e52d3..c0b9a4872c3c4 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/configs/datafeed.ts +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/configs/datafeed.ts @@ -11,6 +11,7 @@ export type DatafeedId = string; export interface Datafeed { datafeed_id: DatafeedId; aggregations?: Aggregation; + aggs?: Aggregation; chunking_config?: ChunkingConfig; frequency?: string; indices: IndexPatternTitle[]; @@ -33,6 +34,7 @@ interface Aggregation { field: string; fixed_interval: string; }; - aggregations: Record; + aggregations?: { [key: string]: any }; + aggs?: { [key: string]: any }; }; } diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts index 90c189c9d6197..5b33aa3556980 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts @@ -623,8 +623,10 @@ export class JobCreator { } this._aggregationFields = []; - if (this._datafeed_config.aggregations?.buckets !== undefined) { - collectAggs(this._datafeed_config.aggregations.buckets, this._aggregationFields); + const buckets = + this._datafeed_config.aggregations?.buckets || this._datafeed_config.aggs?.buckets; + if (buckets !== undefined) { + collectAggs(buckets, this._aggregationFields); } } } diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts index e5b6212a4326e..0764e276d635e 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts @@ -325,7 +325,7 @@ export function collectAggs(o: any, aggFields: Field[]) { if (o[i] !== null && typeof o[i] === 'object') { if (i === 'aggregations' || i === 'aggs') { Object.keys(o[i]).forEach(k => { - if (k !== 'aggregations' && i !== 'aggs') { + if (k !== 'aggregations' && k !== 'aggs') { aggFields.push({ id: k, name: k,