Aggregate Document Value Cardinality
- async AsyncCogniteClient.documents.aggregate_cardinality_values(
- property: DocumentProperty | SourceFileProperty | list[str] | str,
- query: str | None = None,
- filter: Filter | dict[str, Any] | None = None,
- aggregate_filter: AggregationFilter | dict[str, Any] | None = None,
Find approximate property count for documents.
- Parameters:
property (DocumentProperty | SourceFileProperty | list[str] | str) – The property to count the cardinality of.
query (str | None) – The free text search query, for details see the documentation referenced above.
filter (Filter | dict[str, Any] | None) – The filter to narrow down the documents to count cardinality.
aggregate_filter (AggregationFilter | dict[str, Any] | None) – The filter to apply to the resulting buckets.
- Returns:
The number of documents matching the specified filters and search.
- Return type:
int
Examples
Count the number of types of documents in your CDF project:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.documents import DocumentProperty >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> count = client.documents.aggregate_cardinality_values(DocumentProperty.type)
Count the number of authors of plain/text documents in your CDF project:
>>> from cognite.client.data_classes import filters >>> from cognite.client.data_classes.documents import DocumentProperty >>> is_plain_text = filters.Equals(DocumentProperty.mime_type, "text/plain") >>> plain_text_author_count = client.documents.aggregate_cardinality_values( ... DocumentProperty.author, filter=is_plain_text ... )
Count the number of types of documents in your CDF project but exclude documents that start with “text”:
>>> from cognite.client.data_classes.documents import DocumentProperty >>> from cognite.client.data_classes import aggregations >>> agg = aggregations >>> is_not_text = agg.Not(agg.Prefix("text")) >>> type_count_excluded_text = client.documents.aggregate_cardinality_values( ... DocumentProperty.type, aggregate_filter=is_not_text ... )