How nested aggregations work
masterAggregations can be nested by providing a callback function as the final argument to the .aggregation() method. This callback receives the current aggregation object, allowing you to call further .aggregation() methods on it to create a hierarchy.
var body = new Bodybuilder()
.aggregation('terms', 'someField', 'bySomeField',
agg =>
agg
.aggregation('max', 'someOtherField')
.aggregation('missing', 'anotherField')
)
.build();