OLAP Aggregate Queries : Grouping Parameter : Special Grouping Functions : Flattened Multi-level Grouping

Flattened Multi-level Grouping
An aggregate query with multi-level grouping is returned as a nested document. When the TOP, BOTTOM, FIRST, or LAST functions are used, the limit value is normally applied to the corresponding grouping level only. For example:
GET /Email/Message/_aggregate?range=0&m=COUNT(*)
&f=TOP(10,Sender.Person.LastName),Sender.Person.FirstName
This query returns the first 10 Sender.Person.LastName groups, but it returns all FirstName subgroups for each LastName group. The query can be flattened by adding the REST parameter &flat=true:
GET /Email/Message/_aggregate?range=0&m=COUNT(*)
&f=TOP(10,Sender.Person.LastName),Sender.Person.FirstName
&flat=true
This returns only the top 10 LastName/FirstName group pairs. This allows a more predictable result size, e.g., when the results will be displayed in a web page.