2023-10-17 23:36:14 +08:00
|
|
|
[discrete]
|
2023-06-14 22:23:34 +08:00
|
|
|
[[esql-agg-count]]
|
|
|
|
=== `COUNT`
|
2023-12-19 22:59:02 +08:00
|
|
|
|
|
|
|
*Syntax*
|
|
|
|
|
|
|
|
[source,esql]
|
|
|
|
----
|
|
|
|
COUNT([input])
|
|
|
|
----
|
|
|
|
|
|
|
|
*Parameters*
|
|
|
|
|
|
|
|
`input`::
|
|
|
|
Column or literal for which to count the number of values. If omitted, returns a
|
|
|
|
count all (the number of rows).
|
|
|
|
|
|
|
|
*Description*
|
|
|
|
|
|
|
|
Returns the total number (count) of input values.
|
|
|
|
|
|
|
|
*Supported types*
|
|
|
|
|
|
|
|
Can take any field type as input.
|
|
|
|
|
|
|
|
*Examples*
|
2023-06-14 22:23:34 +08:00
|
|
|
|
|
|
|
[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]
|
|
|
|
|===
|
|
|
|
|
2023-12-19 22:59:02 +08:00
|
|
|
To count the number of rows, use `COUNT()` or `COUNT(*)`:
|
2023-10-17 23:36:14 +08:00
|
|
|
|
|
|
|
[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]
|
2023-12-19 22:59:02 +08:00
|
|
|
|===
|