File tree Expand file tree Collapse file tree
x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import {
1919 CREATED_BY_LABEL ,
2020 SHARED_RESULTS_INDEX_NAME ,
2121} from '../../../../../../common/constants/new_job' ;
22- import { isSparseDataJob } from './util/general' ;
22+ import { isSparseDataJob , collectAggs } from './util/general' ;
2323import { parseInterval } from '../../../../../../common/util/parse_interval' ;
2424import { Calendar } from '../../../../../../common/types/calendars' ;
2525import { mlCalendarService } from '../../../../services/calendar_service' ;
@@ -624,27 +624,7 @@ export class JobCreator {
624624
625625 this . _aggregationFields = [ ] ;
626626 if ( this . _datafeed_config . aggregations ?. buckets !== undefined ) {
627- traverseAggs ( this . _datafeed_config . aggregations . buckets , this . _aggregationFields ) ;
628- }
629- }
630- }
631-
632- function traverseAggs ( o : any , aggFields : Field [ ] ) {
633- for ( const i in o ) {
634- if ( o [ i ] !== null && typeof o [ i ] === 'object' ) {
635- if ( i === 'aggregations' || i === 'aggs' ) {
636- Object . keys ( o [ i ] ) . forEach ( k => {
637- if ( k !== 'aggregations' && i !== 'aggs' ) {
638- aggFields . push ( {
639- id : k ,
640- name : k ,
641- type : ES_FIELD_TYPES . KEYWORD ,
642- aggregatable : true ,
643- } ) ;
644- }
645- } ) ;
646- }
647- traverseAggs ( o [ i ] , aggFields ) ;
627+ collectAggs ( this . _datafeed_config . aggregations . buckets , this . _aggregationFields ) ;
648628 }
649629 }
650630}
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 SPARSE_DATA_AGGREGATIONS ,
1313} from '../../../../../../../common/constants/aggregation_types' ;
1414import { MLCATEGORY , DOC_COUNT } from '../../../../../../../common/constants/field_types' ;
15+ import { ES_FIELD_TYPES } from '../../../../../../../../../../../src/plugins/data/public' ;
1516import {
1617 EVENT_RATE_FIELD_ID ,
1718 Field ,
@@ -315,3 +316,26 @@ export function getJobCreatorTitle(jobCreator: JobCreatorType) {
315316 return '' ;
316317 }
317318}
319+
320+ // recurse through a datafeed aggregation object,
321+ // adding top level keys from each nested agg to an array
322+ // of fields
323+ export function collectAggs ( o : any , aggFields : Field [ ] ) {
324+ for ( const i in o ) {
325+ if ( o [ i ] !== null && typeof o [ i ] === 'object' ) {
326+ if ( i === 'aggregations' || i === 'aggs' ) {
327+ Object . keys ( o [ i ] ) . forEach ( k => {
328+ if ( k !== 'aggregations' && i !== 'aggs' ) {
329+ aggFields . push ( {
330+ id : k ,
331+ name : k ,
332+ type : ES_FIELD_TYPES . KEYWORD ,
333+ aggregatable : true ,
334+ } ) ;
335+ }
336+ } ) ;
337+ }
338+ collectAggs ( o [ i ] , aggFields ) ;
339+ }
340+ }
341+ }
You can’t perform that action at this time.
0 commit comments