59 lines
1.2 KiB
Plaintext
59 lines
1.2 KiB
Plaintext
[discrete]
|
|
[[esql-agg-count]]
|
|
=== `COUNT`
|
|
|
|
*Syntax*
|
|
|
|
[source,esql]
|
|
----
|
|
COUNT([expression])
|
|
----
|
|
|
|
*Parameters*
|
|
|
|
`expression`::
|
|
Expression that outputs values to be counted.
|
|
If omitted, equivalent to `COUNT(*)` (the number of rows).
|
|
|
|
*Description*
|
|
|
|
Returns the total number (count) of input values.
|
|
|
|
*Supported types*
|
|
|
|
Can take any field type as input.
|
|
|
|
*Examples*
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/stats.csv-spec[tag=count]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/stats.csv-spec[tag=count-result]
|
|
|===
|
|
|
|
To count the number of rows, use `COUNT()` or `COUNT(*)`:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/docs.csv-spec[tag=countAll]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/docs.csv-spec[tag=countAll-result]
|
|
|===
|
|
|
|
The expression can use inline functions. This example splits a string into
|
|
multiple values using the `SPLIT` function and counts the values:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression-result]
|
|
|===
|