mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
parent
0cd62dd722
commit
e978baa10e
2 changed files with 59 additions and 0 deletions
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue