OLAP Aggregate Queries : Grouping Parameter : Special Grouping Functions : TERMS Function

TERMS Function
Groups can be created from the terms used within a specific field. The general format of the TERMS function is:
TERMS(<field name> [, (<stop term 1> <stop term 2> ...)])
Any predefined scalar field can be used, but TERMS is most effective with text fields. The optional stop term list is a list of terms, enclosed in parentheses, that are excluded from the unique set of terms found within the specified field.
For example, the following request fetches the COUNT of messages grouped by terms found within the Subject field for a particular sender. For brevity, the TERMS function is wrapped by the TOP function to limit the results to the five groups with the highest counts:
GET /Email/Message/_aggregate?m=COUNT(*)&q=Sender.MessageAddress.Person.Name:Support
&f=TOP(5,TERMS(Subject))&shards=2014-06-01
Similar to the BATCH function, the TERMS function creates dynamic groups from a text field based on the terms it uses. To do this, as objects matching the query parameter (if any) are found, the field passed to TERMS is parsed into alphanumeric terms, and a group is created for each unique term. Each contributes to the group metric computation for each term it contains. If a term appears multiple times within a field (e.g., “plan for a plan”), the object is only counted once. An example result in XML is shown below:
<results>
<aggregate query="Sender.MessageAddress.Person.Name:Support" metric="COUNT(*)"
group="TOP(5,TERMS(Subject))"/>
<groups>
<group>
<field name="Subject">dilemmas</field>
<metric>14</metric>
</group>
<group>
<field name="Subject">unchary</field>
<metric>14</metric>
</group>
<group>
<field name="Subject">sundae</field>
<metric>14</metric>
</group>
<group>
<field name="Subject">tillage</field>
<metric>14</metric>
</group>
<group>
<field name="Subject">infernal</field>
<metric>14</metric>
</group>
</groups>
<summary>82</summary>
<totalgroups>85</totalgroups>
</results>
In JSON:
{"results": {
"aggregate": {
"group": "TOP(5,TERMS(Subject))",
"metric": "COUNT(*)",
"query": "Sender.MessageAddress.Person.Name:Support"
},
"groups": [
{"group": {
"field": {"Subject": "dilemmas"},
"metric": "14"
}},
{"group": {
"field": {"Subject": "unchary"},
"metric": "14"
}},
{"group": {
"field": {"Subject": "sundae"},
"metric": "14"
}},
{"group": {
"field": {"Subject": "tillage"},
"metric": "14"
}},
{"group": {
"field": {"Subject": "infernal"},
"metric": "14"
}}
],
"summary": "82",
"totalgroups": "85"
}}
If the terms “sundae” and “tillage” were considered uninteresting, they could be eliminated from the results by listing them as stop terms in a second parenthetical parameter to the TERMS function:
GET /Email/Message/_aggregate?m=COUNT(*)&q=Sender.MessageAddress.Person.Name='Quest Support'
&f=TOP(5,TERMS(Subject,(sundae tillage)))&shards=2014-06-01