const aggregates = await client.assets.aggregate({ filter: { root: true } });
console.log('Number of root assets: ', aggregates[0].count)aggregate_by_prefix = client.assets.aggregate(filter={"external_id_prefix": "prefix"})
from cognite.client.data_classes.assets import AssetProperty
key_count = client.assets.aggregate_cardinality_properties(AssetProperty.metadata)
from cognite.client.data_classes.assets import AssetProperty
label_count = client.assets.aggregate_cardinality_values(AssetProperty.labels)
from cognite.client.data_classes.filters import Search
from cognite.client.data_classes.assets import AssetProperty
is_critical = Search(AssetProperty.description, "critical")
critical_assets = client.assets.aggregate_cardinality_values(
AssetProperty.metadata_key("timezone"),
advanced_filter=is_critical)
count = client.assets.aggregate_count()
from cognite.client.data_classes.filters import ContainsAny
from cognite.client.data_classes.assets import AssetProperty
has_timezone = ContainsAny(AssetProperty.metadata, "timezone")
asset_count = client.assets.aggregate_count(advanced_filter=has_timezone)
from cognite.client.data_classes.assets import AssetProperty
result = client.assets.aggregate_unique_properties(AssetProperty.metadata)
from cognite.client.data_classes.assets import AssetProperty
result = client.assets.aggregate_unique_values(AssetProperty.metadata_key("timezone"))
print(result.unique)
from cognite.client.data_classes import filters
from cognite.client.data_classes.assets import AssetProperty
from cognite.client.utils import timestamp_to_ms
from datetime import datetime
created_after_2020 = filters.Range(AssetProperty.created_time, gte=timestamp_to_ms(datetime(2020, 1, 1)))
result = client.assets.aggregate_unique_values(AssetProperty.labels, advanced_filter=created_after_2020)
print(result.unique)
from cognite.client.data_classes.assets import AssetProperty
from cognite.client.data_classes import aggregations
from cognite.client.data_classes import filters
not_test = aggregations.Not(aggregations.Prefix("test"))
created_after_2020 = filters.Range(AssetProperty.last_updated_time, gte=timestamp_to_ms(datetime(2020, 1, 1)))
result = client.assets.aggregate_unique_values(AssetProperty.labels, advanced_filter=created_after_2020, aggregate_filter=not_test)
print(result.unique)Aggregate aggregateResult = client.assets()
.aggregate(Request.create().withFilterParameter("source", ""));curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"aggregate": "count",
"advancedFilter": {
"and": "<array>"
},
"filter": {
"name": "<string>",
"parentIds": [
4503599627370496
],
"parentExternalIds": [
"my.known.id"
],
"rootIds": [
{
"id": 4503599627370496
}
],
"assetSubtreeIds": [
{
"id": 4503599627370496
}
],
"dataSetIds": [
{
"id": 4503599627370496
}
],
"metadata": {},
"source": "<string>",
"createdTime": {
"max": 1,
"min": 1
},
"lastUpdatedTime": {
"max": 1,
"min": 1
},
"root": true,
"externalIdPrefix": "my.known.prefix",
"labels": {
"containsAny": [
{
"externalId": "my.known.id"
}
]
}
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'aggregate' => 'count',
'advancedFilter' => [
'and' => '<array>'
],
'filter' => [
'name' => '<string>',
'parentIds' => [
4503599627370496
],
'parentExternalIds' => [
'my.known.id'
],
'rootIds' => [
[
'id' => 4503599627370496
]
],
'assetSubtreeIds' => [
[
'id' => 4503599627370496
]
],
'dataSetIds' => [
[
'id' => 4503599627370496
]
],
'metadata' => [
],
'source' => '<string>',
'createdTime' => [
'max' => 1,
'min' => 1
],
'lastUpdatedTime' => [
'max' => 1,
'min' => 1
],
'root' => true,
'externalIdPrefix' => 'my.known.prefix',
'labels' => [
'containsAny' => [
[
'externalId' => 'my.known.id'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate"
payload := strings.NewReader("{\n \"aggregate\": \"count\",\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"aggregate\": \"count\",\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"count": 10
}
]
}{
"error": {
"code": 400,
"message": "`null` values aren't allowed."
}
}{
"error": {
"code": 429,
"message": "Project exceeded maximum number='50' of concurrent requests. Please try again later."
}
}Aggregate assets
Required capabilities:
assetsAcl:READ
The aggregation API lets you compute aggregated results on assets, such as getting the count of all assets in a project, checking different names and descriptions of assets in your project, etc.
Aggregate filtering
Filter (filter & advancedFilter) data for aggregates
Filters behave the same way as for the Filter assets endpoint.
In text properties, the values are aggregated in a case-insensitive manner.
aggregateFilter to filter aggregate results
aggregateFilter works similarly to advancedFilter but always applies to aggregate properties.
For instance, in case of an aggregation for the source property, only the values (aka buckets) of the source property can be filtered out.
Request throttling
This endpoint is meant for data analytics/exploration usage and is not suitable for high load data retrieval usage.
It is a subject of the new throttling schema (limited request rate and concurrency).
Please check Assets resource description for more information.
const aggregates = await client.assets.aggregate({ filter: { root: true } });
console.log('Number of root assets: ', aggregates[0].count)aggregate_by_prefix = client.assets.aggregate(filter={"external_id_prefix": "prefix"})
from cognite.client.data_classes.assets import AssetProperty
key_count = client.assets.aggregate_cardinality_properties(AssetProperty.metadata)
from cognite.client.data_classes.assets import AssetProperty
label_count = client.assets.aggregate_cardinality_values(AssetProperty.labels)
from cognite.client.data_classes.filters import Search
from cognite.client.data_classes.assets import AssetProperty
is_critical = Search(AssetProperty.description, "critical")
critical_assets = client.assets.aggregate_cardinality_values(
AssetProperty.metadata_key("timezone"),
advanced_filter=is_critical)
count = client.assets.aggregate_count()
from cognite.client.data_classes.filters import ContainsAny
from cognite.client.data_classes.assets import AssetProperty
has_timezone = ContainsAny(AssetProperty.metadata, "timezone")
asset_count = client.assets.aggregate_count(advanced_filter=has_timezone)
from cognite.client.data_classes.assets import AssetProperty
result = client.assets.aggregate_unique_properties(AssetProperty.metadata)
from cognite.client.data_classes.assets import AssetProperty
result = client.assets.aggregate_unique_values(AssetProperty.metadata_key("timezone"))
print(result.unique)
from cognite.client.data_classes import filters
from cognite.client.data_classes.assets import AssetProperty
from cognite.client.utils import timestamp_to_ms
from datetime import datetime
created_after_2020 = filters.Range(AssetProperty.created_time, gte=timestamp_to_ms(datetime(2020, 1, 1)))
result = client.assets.aggregate_unique_values(AssetProperty.labels, advanced_filter=created_after_2020)
print(result.unique)
from cognite.client.data_classes.assets import AssetProperty
from cognite.client.data_classes import aggregations
from cognite.client.data_classes import filters
not_test = aggregations.Not(aggregations.Prefix("test"))
created_after_2020 = filters.Range(AssetProperty.last_updated_time, gte=timestamp_to_ms(datetime(2020, 1, 1)))
result = client.assets.aggregate_unique_values(AssetProperty.labels, advanced_filter=created_after_2020, aggregate_filter=not_test)
print(result.unique)Aggregate aggregateResult = client.assets()
.aggregate(Request.create().withFilterParameter("source", ""));curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"aggregate": "count",
"advancedFilter": {
"and": "<array>"
},
"filter": {
"name": "<string>",
"parentIds": [
4503599627370496
],
"parentExternalIds": [
"my.known.id"
],
"rootIds": [
{
"id": 4503599627370496
}
],
"assetSubtreeIds": [
{
"id": 4503599627370496
}
],
"dataSetIds": [
{
"id": 4503599627370496
}
],
"metadata": {},
"source": "<string>",
"createdTime": {
"max": 1,
"min": 1
},
"lastUpdatedTime": {
"max": 1,
"min": 1
},
"root": true,
"externalIdPrefix": "my.known.prefix",
"labels": {
"containsAny": [
{
"externalId": "my.known.id"
}
]
}
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'aggregate' => 'count',
'advancedFilter' => [
'and' => '<array>'
],
'filter' => [
'name' => '<string>',
'parentIds' => [
4503599627370496
],
'parentExternalIds' => [
'my.known.id'
],
'rootIds' => [
[
'id' => 4503599627370496
]
],
'assetSubtreeIds' => [
[
'id' => 4503599627370496
]
],
'dataSetIds' => [
[
'id' => 4503599627370496
]
],
'metadata' => [
],
'source' => '<string>',
'createdTime' => [
'max' => 1,
'min' => 1
],
'lastUpdatedTime' => [
'max' => 1,
'min' => 1
],
'root' => true,
'externalIdPrefix' => 'my.known.prefix',
'labels' => [
'containsAny' => [
[
'externalId' => 'my.known.id'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate"
payload := strings.NewReader("{\n \"aggregate\": \"count\",\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/aggregate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"aggregate\": \"count\",\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"count": 10
}
]
}{
"error": {
"code": 400,
"message": "`null` values aren't allowed."
}
}{
"error": {
"code": 429,
"message": "Project exceeded maximum number='50' of concurrent requests. Please try again later."
}
}Authorizations
Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.
Body
- AssetCount
- AssetWithPropertyCount
- ApproximateCardinalityForValues
- ApproximateCardinalityForProperties
- UniqueValues
- UniqueProperties
- MetadataKeys
- MetadataValues
Aggregation request of assets. Filters behave the same way as for the filter endpoint. Default aggregation is count.
Type of aggregation to apply.
count: Get approximate number of Assets matching the filters.
count A query that matches items matching boolean combinations of other queries.
It is built using one or more boolean clauses of the following types: and, or, or not.
- and
- or
- not
- equals
- in
- range
- prefix
- exists
- containsAny
- containsAll
- search
Show child attributes
Show child attributes
Filter on assets with strict matching.
Show child attributes
Show child attributes
Response
Response with a list of aggregation results.
- CountResult
- BucketsResult
Common aggregate structure to represent aggregate result which have one count for filter resultset (Documents Count, Property Cardinality, etc).
1 elementShow child attributes
Show child attributes
Was this page helpful?