The aggregation API allows you to compute aggregated results from a set of sequences, such as
getting the number of sequences in a project or checking what assets the different sequences
in your project are associated with (along with the number of sequences for each asset).
By specifying filter
and/or advancedFilter
, the aggregation will take place only over those
sequences that match the filters. filter
and advancedFilter
behave the same way as in the
list
endpoint.
aggregate
field is not specified the request body, is to return the
number of sequences that match the filters (if any), which is the same behavior as when the
aggregate
field is set to count
.
The following requests will both return the total number of
sequences whose name
begins with pump
:
{
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}}
}
and
{
"aggregate": "count",
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}}
}
The response might be:
{"items": [{"count": 42}]}
aggregate
to uniqueValues
and specifying a property in properties
(this field is an array, but currently only supports one property) will
return all unique values (up to a maximum of 1000) that are taken on by that property
across all the sequences that match the filters, as well as the number of sequences that
have each of those property values.
This example request finds all the unique asset ids that are
referenced by the sequences in your project whose name
begins with pump
:
{
"aggregate": "uniqueValues",
"properties": [{"property": ["assetId"]}],
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}}
}
The response might be the following, saying that 23 sequences are associated with asset 18 and 107 sequences are associated with asset 76:
{
"items": [
{"values": ["18"], "count": 23},
{"values": ["76"], "count": 107}
]
}
aggregate
to cardinalityValues
will instead return the approximate number of
distinct values that are taken on by the given property among the matching sequences.
Example request:
{
"aggregate": "cardinalityValues",
"properties": [{"property": ["assetId"]}],
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}}
}
The result is likely exact when the set of unique values is small. In this example, there are likely two distinct asset ids among the matching sequences:
{"items": [{"count": 2}]}
aggregate
to uniqueProperties
will return the set of unique properties whose property
path begins with path
(which can currently only be ["metadata"]
) that are contained in the sequences that match the filters.
Example request:
{
"aggregate": "uniqueProperties",
"path": ["metadata"],
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}}
}
The result contains all the unique metadata keys in the sequences whose name
begins with
pump
, and the number of sequences that contains each metadata key:
{
"items": [
{"values": [{"property": ["metadata", "tag"]}], "count": 43},
{"values": [{"property": ["metadata", "installationDate"]}], "count": 97}
]
}
aggregate
to cardinalityProperties
will instead return the approximate number of
different property keys whose path begins with path
(which can currently only be ["metadata"]
, meaning that this can only be used to count the approximate number of distinct metadata keys among the matching sequences).
Example request:
{
"aggregate": "cardinalityProperties",
"path": ["metadata"],
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}}
}
The result is likely exact when the set of unique values is small. In this example, there are likely two distinct metadata keys among the matching sequences:
{"items": [{"count": 2}]}
The aggregateFilter
field may be specified if aggregate
is set to cardinalityProperties
or uniqueProperties
. The structure of this field is similar to that of advancedFilter
, except that the set of leaf filters is smaller (in
, prefix
, and range
), and that none of the leaf filters specify a property. Unlike advancedFilter
, which is applied before the aggregation (in order to restrict the set of sequences that the aggregation operation should be applied to), aggregateFilter
is applied after the initial aggregation has been performed, in order to restrict the set of results.
aggregateFilter
.
When aggregate
is set to uniqueProperties
, the result set contains a number of property paths, each with an associated count that shows how many sequences contained that property (among those sequences that matched the filter
and advancedFilter
, if they were specified) . If aggregateFilter
is specified, it will restrict the property paths included in the output. Let us add an aggregateFilter
to the uniqueProperties
example from above:
{
"aggregate": "uniqueProperties",
"path": ["metadata"],
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}},
"aggregateFilter": {"prefix": {"value": "t"}}
}
Now, the result only contains those metadata properties whose key begins with t
(but it will be the same set of metadata properties that begin with t
as in the original query without aggregateFilter
, and the counts will be the same):
{
"items": [
{"values": [{"property": ["metadata", "tag"]}], "count": 43}
]
}
Similarly, adding aggregateFilter
to cardinalityProperties
will return the approximate number of properties whose property key matches aggregateFilter
from those sequences matching the filter
and advancedFilter
(or from all sequences if neither filter
nor aggregateFilter
are specified):
{
"aggregate": "cardinalityProperties",
"path": ["metadata"],
"advancedFilter": {"prefix": {"property": ["name"], "value": "pump"}},
"aggregateFilter": {"prefix": {"value": "t"}}
}
As we saw above, only one property matches:
{"items": [{"count": 1}]}
Note that aggregateFilter
is also accepted when aggregate
is set to cardinalityValues
or cardinalityProperties
. For those aggregations, the effect of any aggregateFilter
could also be achieved via a similar advancedFilter
. However, aggregateFilter
is not accepted when aggregate
is omitted or set to count
.
Rate and concurrency limits apply this endpoint. If a request exceeds one of the limits,
it will be throttled with a 429: Too Many Requests
response. More on limit types
and how to avoid being throttled is described
here.
Limit | Per project | Per user (identity) |
---|---|---|
Rate | 15 requests per second | 10 requests per second |
Concurrency | 6 concurrent requests | 4 concurrent requests |
Aggregates the sequences that match the given criteria.
Response with the aggregated sequences. The type of the response depends on the value of the aggregate
parameter in the request.
The response for a failed request.
{- "advancedFilter": {
- "or": [
- {
- "not": {
- "and": [
- {
- "equals": {
- "property": [
- "metadata",
- "manufacturer"
], - "value": "acme"
}
}, - {
- "in": {
- "property": [
- "name"
], - "values": [
- "pump-1-temperature",
- "motor-9-temperature"
]
}
}, - {
- "range": {
- "property": [
- "dataSetId"
], - "gte": 1,
- "lt": 10
}
}
]
}
}, - {
- "and": [
- {
- "equals": {
- "property": [
- "assetId"
], - "value": 1234
}
}, - {
- "equals": {
- "property": [
- "description"
], - "value": "Temperature in Celsius"
}
}
]
}
]
}, - "aggregateFilter": {
- "and": [
- { }
]
}, - "filter": {
- "name": "string",
- "externalIdPrefix": "my.known.prefix",
- "metadata": {
- "key1": "value1",
- "key2": "value2"
}, - "assetIds": [
- 363848954441724,
- 793045462540095,
- 1261042166839739
], - "rootAssetIds": [
- 363848954441724,
- 793045462540095,
- 1261042166839739
], - "assetSubtreeIds": [
- {
- "id": 1234567890
}, - {
- "externalId": "externalId123"
}
], - "createdTime": {
- "max": 0,
- "min": 0
}, - "lastUpdatedTime": {
- "max": 0,
- "min": 0
}, - "dataSetIds": [
- {
- "id": 1
}
]
}, - "aggregate": "count"
}
{- "items": [
- {
- "count": 0
}
]
}