Skip to content

Commit

Permalink
[ML] Fixing "aggs" use in datafeeds (#56002) (#56016)
Browse files Browse the repository at this point in the history
* [ML] Fixing "aggs" use in datafeeds

* removing use of Record
  • Loading branch information
jgowdyelastic authored Jan 27, 2020
1 parent a20ace3 commit c860fab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -33,6 +34,7 @@ interface Aggregation {
field: string;
fixed_interval: string;
};
aggregations: Record<string, any>;
aggregations?: { [key: string]: any };
aggs?: { [key: string]: any };
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c860fab

Please sign in to comment.