Documentation

influxdb.cardinality() function

influxdb.cardinality() returns the series cardinality of data retrieved from InfluxDB.

Although this function is similar to InfluxQL’s SHOW SERIES CARDINALITY, it works in a slightly different manner.

influxdb.cardinality() is time bounded and reports the cardinality of data that matches the conditions passed into it rather than that of the bucket as a whole.

Function type signature
(
    start: A,
    ?bucket: string,
    ?bucketID: string,
    ?host: string,
    ?org: string,
    ?orgID: string,
    ?predicate: (r: {B with _value: C, _measurement: string, _field: string}) => bool,
    ?stop: D,
    ?token: string,
) => stream[{_value: int, _stop: time, _start: time}] where A: Timeable, D: Timeable
  • Copy
  • Fill window

For more information, see Function type signatures.

Parameters

bucket

Bucket to query cardinality from.

bucketID

String-encoded bucket ID to query cardinality from.

org

Organization name.

orgID

String-encoded organization ID.

host

URL of the InfluxDB instance to query.

See InfluxDB Cloud regions or InfluxDB OSS URLs.

token

InfluxDB API token.

start

(Required) Earliest time to include when calculating cardinality.

The cardinality calculation includes points that match the specified start time. Use a relative duration or absolute time. For example, -1h or 2019-08-28T22:00:00Z. Durations are relative to now().

stop

Latest time to include when calculating cardinality.

The cardinality calculation excludes points that match the specified start time. Use a relative duration or absolute time. For example, -1h or 2019-08-28T22:00:00Z. Durations are relative to now(). Default is now().

The default value is now(), so any points that have been written into the future will not be counted unless a future stop date is provided.

predicate

Predicate function that filters records. Default is (r) => true.

Examples

Query series cardinality in a bucket

import "influxdata/influxdb"

influxdb.cardinality(bucket: "example-bucket", start: time(v: 1))
  • Copy
  • Fill window

Note: if points have been written into the future, you will need to add an appropriate stop date

Query series cardinality in a measurement//

import "influxdata/influxdb"

influxdb.cardinality(
    bucket: "example-bucket",
    start: time(v: 1),
    predicate: (r) => r._measurement == "example-measurement",
)
  • Copy
  • Fill window

Query series cardinality for a specific tag

import "influxdata/influxdb"

influxdb.cardinality(bucket: "example-bucket", start: time(v: 1), predicate: (r) => r.exampleTag == "foo")
  • Copy
  • Fill window

Query Cardinality of Data Written In the Last 4 hours

import "influxdata/influxdb"

influxdb.cardinality(bucket: "example-bucket", start: -4h)
  • Copy
  • Fill window

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: