mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
* Document nested expressions for stats * More docs * Apply suggestions from review - count-distinct.asciidoc - Content restructured, moving the section about approximate counts to end of doc. - count.asciidoc - Clarified that omitting the `expression` parameter in `COUNT` is equivalent to `COUNT(*)`, which counts the number of rows. - percentile.asciidoc - Moved the note about `PERCENTILE` being approximate and non-deterministic to end of doc. - stats.asciidoc - Clarified the `STATS` command - Added a note indicating that individual `null` values are skipped during aggregation * Comment out mentioning a buggy behavior * Update sum with inline function example, update test file * Fix typo * Delete line * Simplify wording * Fix conflict fix typo --------- Co-authored-by: Liam Thompson <leemthompo@gmail.com> Co-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>
58 lines
1.2 KiB
Text
58 lines
1.2 KiB
Text
[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]
|
|
|===
|