CMS-4650 Implement support for nested aggregations

Quick and dirty.