Skip to content

Commit

Permalink
Add referenced pipeline aggs to every level of query (#31121) (#31710)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Feb 22, 2019
1 parent 0a2f7d1 commit 55c84b4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/legacy/ui/public/vis/__tests__/_agg_configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,57 @@ describe('AggConfigs', function () {
}
}(topLevelDsl));
});

it('adds the parent aggs of nested metrics at every level if the vis is hierarchical', function () {
const vis = new Vis(indexPattern, {
type: 'histogram',
aggs: [
{
id: '1',
type: 'avg_bucket',
schema: 'metric',
params: {
customBucket: {
id: '1-bucket',
type: 'date_histogram',
schema: 'bucketAgg',
params: {
field: '@timestamp'
}
},
customMetric: {
id: '1-metric',
type: 'count',
schema: 'metricAgg',
params: {}
}
}
},
{
id: '2',
type: 'terms',
schema: 'bucket',
params: {
field: 'geo.src',
}
},
{
id: '3',
type: 'terms',
schema: 'bucket',
params: {
field: 'machine.os',
}
}
]
});
vis.isHierarchical = _.constant(true);

const topLevelDsl = vis.aggs.toDsl(vis.isHierarchical())['2'];
expect(topLevelDsl.aggs).to.have.keys(['1', '1-bucket']);
expect(topLevelDsl.aggs['1'].avg_bucket).to.have.property('buckets_path', '1-bucket>_count');
expect(topLevelDsl.aggs['3'].aggs).to.have.keys(['1', '1-bucket']);
expect(topLevelDsl.aggs['3'].aggs['1'].avg_bucket).to.have.property('buckets_path', '1-bucket>_count');
});
});
});
7 changes: 7 additions & 0 deletions src/legacy/ui/public/vis/agg_configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ class AggConfigs extends IndexedArray {
if (subAggs && nestedMetrics) {
nestedMetrics.forEach(agg => {
subAggs[agg.config.id] = agg.dsl;
// if a nested metric agg has parent aggs, we have to add them to every level of the tree
// to make sure "bucket_path" references in the nested metric agg itself are still working
if (agg.dsl.parentAggs) {
Object.entries(agg.dsl.parentAggs).forEach(([parentAggId, parentAgg]) => {
subAggs[parentAggId] = parentAgg;
});
}
});
}
});
Expand Down

0 comments on commit 55c84b4

Please sign in to comment.