Spider Aggregate Queries : Grouping Parameter : Compound/Multi-metric Grouping Results

Compound/Multi-metric Grouping Results
Multi-metric aggregate queries can also use compound grouping. That is, a single aggregate query can specify multiple metric functions in the &m parameter and multiple GROUP functions in the &f or &cf parameter. Such queries compute multiple metric functions, like a multi-metric query, and provide multiple grouping operations for each metric, all in a single query.
The results of compound/multi-metric queries are returned using groupset elements for each combination of metric function and GROUP function. If there are m metric functions and n GROUP functions, the result will contain m x n groupset elements. Each groupset identifies the metric and grouping parameter for which it provides results.
As an example, the following compound/multi-metric aggregate query has 3 metric functions and 2 GROUP functions:
GET /Msgs/Message/_aggregate?m=COUNT(*),MAX(Size),AVERAGE(Size)
&cf=GROUP(TOP(2,Tags),Subject),GROUP(TRUNCATE(SendDate,DAY))
This means the result will contain 6 groupset elements, as shown in the following XML outline:
<results>
<aggregate metric="COUNT(*),MAX(Size),AVERAGE(Size)" group="GROUP(TOP(2,Tags),Subject),GROUP(TRUNCATE(SendDate,DAY))"/>
<groupsets>
<groupset group="TOP(2,Tags),Subject" metric="COUNT(*)">...</groupset>
<groupset group="TRUNCATE(SendDate,DAY)" metric="COUNT(*)">...</groupset>
<groupset group="TOP(2,Tags),Subject" metric="MAX(Size)">...</groupset>
<groupset group="TRUNCATE(SendDate,DAY)" metric="MAX(Size)">...</groupset>
<groupset group="TOP(2,Tags),Subject" metric="AVERAGE(Size)">...</groupset>
<groupset group="TRUNCATE(SendDate,DAY)" metric="AVERAGE(Size)">...</groupset>
</groupsets>
</results>
In JSON:
{"results": {
"aggregate": {
"group": "GROUP(TOP(2,Tags),Origin),GROUP(TRUNCATE(SendDate,DAY))",
"metric": "COUNT(*),MAX(Size),AVERAGE(Size)"
},
"groupsets": [
{"groupset": {"group": "TOP(2,Subject),Origin", "metric": "COUNT(*)", ...}},
{"groupset": {"group": "TRUNCATE(SendDate,DAY)", "metric": "COUNT(*)", ...}},
{"groupset": {"group": "TOP(2,Subject),Origin", "metric": "MAX(Size)", ...}},
{"groupset": {"group": "TRUNCATE(SendDate,DAY)", "metric": "MAX(Size)", ...},
{"groupset": {"group": "TOP(2,Subject),Origin", "metric": "AVERAGE(Size)", ...}},
{"groupset": {"group": "TRUNCATE(SendDate,DAY)", "metric": "AVERAGE(Size)", ...}}
]
}}
Though not shown here, each groupset will contain groups, summary, and totalgroups elements as required by each GROUP function. If the query requests composite grouping (&cf), a groupset with multi-level grouping will contain a composite group for non-leaf groups.