2025-06-21 03:42:37 +08:00
% This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it.
2025-03-04 21:59:31 +08:00
**Examples**
```esql
FROM employees
| STATS COUNT(height)
```
| COUNT(height):long |
| --- |
| 100 |
To count the number of rows, use `COUNT()` or `COUNT(*)`
```esql
FROM employees
| STATS count = COUNT(*) BY languages
| SORT languages DESC
```
| count:long | languages:integer |
| --- | --- |
| 10 | null |
| 21 | 5 |
| 18 | 4 |
| 17 | 3 |
| 19 | 2 |
| 15 | 1 |
The expression can use inline functions. This example splits a string into multiple values using the `SPLIT` function and counts the values
```esql
ROW words="foo;bar;baz;qux;quux;foo"
| STATS word_count = COUNT(SPLIT(words, ";"))
```
| word_count:long |
| --- |
| 6 |
Split ES|QL functions/operators/commands into separate pages for similar functions and make commands examples generated (#126279)
While the internal structure of the docs is already split into many (over 1000) sub-pages, the final display for the `Functions and Operators` page is a single giant page, making navigation harder. This PR splits it into separate pages, one for each group of similar functions and one for the operators. Twelve new pages.
This PR also bundles a few other related changes. In total what is done is:
* Split functions/operators into 12 pages, one for each group, maintaining the existing split of each function/operator into a snippet with dynamically generated examples
* Split esql-commands.md into source-commands.md and processing-commands.md, each of which is split into individual snippets, one for each command
* Each command snippet has it's examples split out into separate files, if they were examples that were dynamically generated in the older asciidoc system
* The examples files are overwritten by the ES|QL unit tests, using a similar mechanism to the examples written for functions and operators)
* Some additional refinements to the Kibana definition and markdown files (nicer operator headings, and display text)
2025-04-10 21:56:05 +08:00
To count the number of times an expression returns `TRUE` use a [`WHERE` ](/reference/query-languages/esql/commands/processing-commands.md#esql-where ) command to remove rows that shouldn’ t be included
2025-03-04 21:59:31 +08:00
```esql
ROW n=1
| WHERE n < 0
| STATS COUNT(n)
```
| COUNT(n):long |
| --- |
| 0 |
2025-03-13 21:16:46 +08:00
To count the same stream of data based on two different expressions use the pattern `COUNT(<expression> OR NULL)` . This builds on the three-valued logic ([3VL](https://en.wikipedia.org/wiki/Three-valued_logic)) of the language: `TRUE OR NULL` is `TRUE` , but `FALSE OR NULL` is `NULL` , plus the way COUNT handles `NULL` s: `COUNT(TRUE)` and `COUNT(FALSE)` are both 1, but `COUNT(NULL)` is 0.
2025-03-04 21:59:31 +08:00
```esql
ROW n=1
| STATS COUNT(n > 0 OR NULL), COUNT(n < 0 OR NULL )
```
| COUNT(n > 0 OR NULL):long | COUNT(n < 0 OR NULL ) :long |
| --- | --- |
| 1 | 0 |