Skip to main content

COUNT / SELECT COUNT(*)

Note

SDK methods: query.

Syntax

{ COUNT | SELECT COUNT(*) } FROM collection_name
[PARTITION partition_name] [WHERE scalar_condition]
[WITH (option = value [, ...])];

Count Statistics

Use COUNT FROM ... or SELECT COUNT(*) FROM ... to count entities in a collection or partition. Both use the same native Milvus count request, without scanning results on the client. The result is one row with COUNT (BIGINT), read using rs.getLong("COUNT"); an empty match returns 0. Append WITH for query-level options; ignore_growing=true also excludes growing segments from counts.

-- Query total count of full table
count from table_name;
SELECT COUNT(*) FROM table_name;

-- Query total count of specific partition
COUNT FROM table_name PARTITION partition_name;

-- Count with conditional filtering (supports scalar filtering)
count from table_name where age > 18;

Aggregation and Deduplication Limits

COUNT(*) counts records matching scalar conditions. The Builder API's queryForCount() is also supported.

COUNT(field), COUNT(DISTINCT field), DISTINCT, GROUP BY, SUM, and MAX are unsupported. A query cannot mix aggregate values with ordinary fields. These limits also apply to statements generated by the Builder API.

COUNT does not accept vector-range conditions. To group similarity-search matches by category, use vector grouping search; it returns matching entities, not per-group aggregates.