Skip to content

Commit

Permalink
picking all agg keys for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jan 20, 2020
1 parent 03f0470 commit ef56b0e
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -626,25 +626,23 @@ export class JobCreator {
if (this._datafeed_config.aggregations?.buckets !== undefined) {
traverseAggs(this._datafeed_config.aggregations.buckets, this._aggregationFields);
}
// if (this._scriptFields.length) {
// this._fields
// }
}
}

function traverseAggs(o: any, aggFields: Field[]) {
for (const i in o) {
if (o[i] !== null && typeof o[i] === 'object') {
if (i === 'aggregations' || i === 'aggs') {
const aggFieldName = Object.keys(o[i])[0];
if (aggFieldName !== undefined) {
aggFields.push({
id: aggFieldName,
name: aggFieldName,
type: ES_FIELD_TYPES.KEYWORD,
aggregatable: true,
});
}
Object.keys(o[i]).forEach(k => {
if (k !== 'aggregations' && i !== 'aggs') {
aggFields.push({
id: k,
name: k,
type: ES_FIELD_TYPES.KEYWORD,
aggregatable: true,
});
}
});
}
traverseAggs(o[i], aggFields);
}
Expand Down

0 comments on commit ef56b0e

Please sign in to comment.