-
Notifications
You must be signed in to change notification settings - Fork 22
Metric Parameter for Object Queries (OLAP)
[Table of Contents](https://github.com/dell-oss/Doradus/wiki/OLAP Databases: Table-of-Contents) | Previous | Next
OLAP Object Queries: Metric Parameter for Object Queries
In an object query, the metric parameter returns one or more metric computations for each selected object. These computed values are in addition to the field values specified by the fields parameter. The syntax for the metric parameter is the same as in aggregate queries: it is a comma-separated list of metric expressions. Each metric expression is an algebraic expression using metric functions, arithmetic operators, and parentheses. See the section [Metric Parameter for Aggregate Queries](https://github.com/dell-oss/Doradus/wiki/Metric Parameter for Aggregate Queries (OLAP)) for full details. Below is an example object query with a single metric function:
GET /Email/Person/_query?shards=s1&m=COUNT(Messages.MessageAsSender)&f=FirstName,LastName
This query selects all Person
objects and returns their FirstName
and LastName
fields. Additionally, the metric parameter returns the COUNT
of all Messages.MessageAsSender
values for each object. The metric expression result is returned as an additional field element whose name equals the metric expression text. Example:
<results>
<totalobjects>185</totalobjects>
<docs>
<doc>
<field name="COUNT(Messages.MessageAsSender)">3</field>
<field name="FirstName">Chris</field>
<field name="LastName">Rudd</field>
<field name="_ID">+IBGjRcg4dMXgu3l7aOZXg==</field>
<field name="_shard">s1</field>
</doc>
<doc>
<field name="COUNT(Messages.MessageAsSender)">9</field>
<field name="FirstName">Scott</field>
<field name="LastName">Reasoner</field>
<field name="_ID">+eVQDWAtRBSjWc6DHYVtTg==</field>
<field name="_shard">s1</field>
</doc>
...
</docs>
<results>
The field name used for the metric function can be customized for easier recognition using the AS
syntax. Example:
GET /Email/Person/_query?shards=s1&m=COUNT(Messages.MessageAsSender) AS 'Messages Sent'
&f=FirstName,LastName
The name following AS can be a simple term or a quoted string. Multiple expressions can be computed by the metrics parameter by separating each expression by a comma. For example, suppose we want to know the total number of messages sent by each person and the total size of all sent messages. The following query could be used:
GET /Email/Person/_query?range=0&f=FirstName,LastName
&m=COUNT(Messages.MessageAsSender) AS TotalMessages, SUM(Messages.MessageAsSender.Size) AS TotalSize
Below is an example where a metric computation uses an algebraic expression to compute a more complex result:
GET /Email/Person/_query?range=0&f=FirstName,LastName
&m=COUNT(DirectReports^.WHERE(LastName:smith)) + COUNT(Manager^.WHERE(Department:support))
In addition to FirstName
and LastName
, this query returns for each person the sum of (1) the count of all DirectReports
transitively (“down” the org chart) whose LastName
contains the term “smith”, and (2) the count of all Managers
transitively (“up” the org chart) whose Department
contains the term “support”.
Technical Documentation
[Doradus OLAP Databases](https://github.com/dell-oss/Doradus/wiki/Doradus OLAP Databases)
- Architecture
- OLAP Database Overview
- OLAP Data Model
- Doradus Query Language (DQL)
- OLAP Object Queries
- OLAP Aggregate Queries
- OLAP REST Commands
- Architecture
- Spider Database Overview
- Spider Data Model
- Doradus Query Language (DQL)
- Spider Object Queries
- Spider Aggregate Queries
- Spider REST Commands
- [Installing and Running Doradus](https://github.com/dell-oss/Doradus/wiki/Installing and Running Doradus)
- [Deployment Guidelines](https://github.com/dell-oss/Doradus/wiki/Deployment Guidelines)
- [Doradus Configuration and Operation](https://github.com/dell-oss/Doradus/wiki/Doradus Configuration and Operation)
- [Cassandra Configuration and Operation](https://github.com/dell-oss/Doradus/wiki/Cassandra Configuration and Operation)