Skip to content

count

Description

The count command returns a single row representing the total number of documents in the current result set. It can optionally store this result in a named keypath for readability using the into keyword.

Syntax

count [into <keypath>]

Example

Use case: Count the number of HTTP request logs

We have log entries representing HTTP requests, each with a status_code field. Using count, we can determine the total number of requests that include a status code, optionally saving the result under a custom name for clarity.

Example data

{ "status_code": 200, "path": "/home" },
{ "status_code": 404, "path": "/not-found" },
{ "status_code": 500, "path": "/checkout" }

Example query

filter status_code != null
| count into http_request_count

Example output

http_request_count
3

The count command aggregates the number of documents that meet the filter condition and returns the total as a single record. In this case, all three documents contained a status_code.