Aggregate Document Count

async AsyncCogniteClient.documents.aggregate_count(
query: str | None = None,
filter: Filter | dict[str, Any] | None = None,
) int

Count of documents matching the specified filters and search.

Parameters:
  • 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.

Returns:

The number of documents matching the specified filters and search.

Return type:

int

Examples

Count the number of documents in your CDF project:

>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> count = client.documents.aggregate_count()

Count the number of PDF documents in your CDF project:

>>> from cognite.client.data_classes import filters
>>> from cognite.client.data_classes.documents import DocumentProperty
>>> is_pdf = filters.Equals(DocumentProperty.mime_type, "application/pdf")
>>> pdf_count = client.documents.aggregate_count(filter=is_pdf)

Count the number of documents with a related asset in a subtree rooted at any of the specified external IDs, e.g. ‘Plant_1’ and ‘Plant_2’:

>>> client.documents.aggregate_count(
...     filter=filters.InAssetSubtree(
...         property=DocumentProperty.asset_external_ids,
...         values=["Plant_1", "Plant_2"],
...     )
... )