-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add documentation for TS source #134373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add documentation for TS source #134373
Changes from 5 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
6463013
Add documentation for TS source
kkrik-es 8677ce0
add toc ref
kkrik-es 49630b7
update nav
kkrik-es 3beebc4
update
kkrik-es 4104e1a
Merge branch 'main' into tsdb/ts-doc
marciw c860567
Apply suggestions from code review
kkrik-es 5d23ffe
Update ts.md
kkrik-es 4ec4daf
Merge branch 'main' into tsdb/ts-doc
kkrik-es 2feaffc
Apply suggestions from code review
kkrik-es d9e9451
update
kkrik-es fd54d14
add links to time-series functions
kkrik-es 7dbd092
restore brief description
kkrik-es 54f994b
fix formatting
kkrik-es b299ec4
remove links
kkrik-es 0e56b47
Apply suggestions from code review
kkrik-es 9b3bb28
Update ts.md
kkrik-es e452620
Update ts.md
kkrik-es bf342c2
Update ts.md
kkrik-es 9b557ce
Merge branch 'main' into tsdb/ts-doc
kkrik-es 647534c
Merge branch 'refs/heads/main' into tsdb/ts-doc
kkrik-es 8afa050
update
kkrik-es a83f082
Merge remote-tracking branch 'origin/tsdb/ts-doc' into tsdb/ts-doc
kkrik-es 5cb5f45
Merge branch 'main' into tsdb/ts-doc
kkrik-es 086fece
mark over time functions as preview
kkrik-es a376340
Merge branch 'main' into tsdb/ts-doc
kkrik-es 020d26b
add time-series aggs
kkrik-es ef0611f
Merge remote-tracking branch 'origin/tsdb/ts-doc' into tsdb/ts-doc
kkrik-es cd670c1
list time-series aggs
kkrik-es 51b2170
add missing
kkrik-es e499726
add toc
kkrik-es bd2f557
remove snapshot notes
kkrik-es a9cc818
add title
kkrik-es cd4ed00
sum_over_time example
kkrik-es 8954b44
fix ts agg refs
kkrik-es 1d25d54
add links to TS doc
kkrik-es 8545d17
fix links to TS doc
kkrik-es c9a21d4
fix links to TS doc
kkrik-es 9e192d9
Merge branch 'main' into tsdb/ts-doc
kkrik-es 4d7e593
remove note
kkrik-es f32b1ff
Merge branch 'main' into tsdb/ts-doc
kkrik-es ee1df8b
Apply suggestions from code review
kkrik-es 9276b86
Update ts.md
kkrik-es b0600a9
Apply suggestions from code review
kkrik-es aa587e8
Apply suggestions from code review
kkrik-es 1f17af3
update function description
kkrik-es 71fa400
Update docs/reference/query-languages/esql/_snippets/commands/layout/…
kkrik-es 013a5e0
Merge branch 'main' into tsdb/ts-doc
kkrik-es 2b1832c
Apply suggestions from code review
kkrik-es 59541ae
Merge branch 'main' into tsdb/ts-doc
kkrik-es a2706ea
fix from review
kkrik-es 2921961
Update ts.md
kkrik-es File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,120 @@ | ||
| ```yaml {applies_to} | ||
| serverless: ga | ||
| stack: ga | ||
| serverless: tech-preview | ||
| stack: tech-preview 9.2.0 | ||
| ``` | ||
|
|
||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| The `TS` command is similar to the `FROM` source command, | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| but with two key differences: it targets only [time-series indices](docs-content://manage-data/data-store/data-streams/time-series-data-stream-tsds.md) | ||
| and enables the use of time-series aggregation functions | ||
| with the [STATS](/reference/query-languages/esql/commands/stats-by.md) command. | ||
| with the following key differences: | ||
|
|
||
| - Targets only [time-series indices](docs-content://manage-data/data-store/data-streams/time-series-data-stream-tsds.md) | ||
| - Propagates the metadata fields [`_tsid`](docs-content://manage-data/data-store/data-streams/time-series-data-stream-tsds.md#tsid) | ||
| and `@timestamp` to the next operators, | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| even if they are not mentioned explicitly | ||
| - Enables the use of time-series aggregation functions inside the | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [STATS](/reference/query-languages/esql/commands/stats-by.md) command | ||
|
|
||
| The `TS` command is expected to be used in conjunction with the `STATS` command | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| to perform time-series analysis. `STATS` behaves polymorphically in this context, | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| enabling the use of time-series aggregation functions such as `last_over_time()`, | ||
| or `rate`. These functions are implicitly evaluated per `_tsid` | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (per time-series), with their results then aggregated per grouping bucket using | ||
| a secondary aggregation function. More concretely, consider the following query: | ||
|
|
||
| ```esql | ||
| TS metrics | ||
| | WHERE @timestamp >= now() - 1 hour | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | STATS total_rate=SUM(RATE(search_requests)) BY hourly=TBUCKET(1 hour), host | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| This query calculates the total rate of search requests (tracked through | ||
| counter `search`) per host-hour. Here, the `rate()` function is first | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| applied per `_tsid` and hourly time bucket, with the results then summed per | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| host and hourly bucket, as each host value may map to many `_tsid` values | ||
| (`_tsid` is calculated on all dimension values). | ||
|
|
||
| ::::{note} | ||
| Metric fields are part of the time-series definition, so there is no point to | ||
| include null metric values in these queries. Therefore, null metric values get | ||
| filtered out implicitly under the `TS` command. | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| :::: | ||
|
|
||
| This paradigm with a pair of aggregation functions is standard for time-series | ||
| querying. Supported inner (time-series) functions per | ||
| [metric type](docs-content://manage-data/data-store/data-streams/time-series-data-stream-tsds.md#time-series-metric) | ||
| include: | ||
|
|
||
| - `LAST_OVER_TIME()`: applies to gauges and counters | ||
|
||
| - `FIRST_OVER_TIME()`: applies to gauges and counters | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `RATE()`: applies to counters only | ||
| - `MIN_OVER_TIME()`: applies to gauges only | ||
| - `MAX_OVER_TIME()`: applies to gauges only | ||
| - `SUM_OVER_TIME()`: applies to gauges only | ||
| - `COUNT_OVER_TIME()`: applies to gauges only | ||
| - `AVG_OVER_TIME()`: applies to gauges only | ||
| - `PRESENT_OVER_TIME()`: applies to gauges only' | ||
| - `ABSENT_OVER_TIME()`: applies to gauges only' | ||
|
|
||
| These functions are supported for downsampled data too, with the same semantics | ||
| as for raw data. For instance, `RATE()` applies to downsampled counters only, | ||
| not gauges. No change in the syntax is required to query a time-series data | ||
| stream containing mixed raw and downsampled data. | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ::::{note} | ||
| If a query is missing an inner (time-series) aggregation function, | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| `LAST_OVER_TIME()` is assumed and used implicitly. For instance, the following | ||
| two queries are equivalent, returning the average of the last memory usage | ||
| values per time-series: | ||
|
|
||
| ```esql | ||
| TS metrics | STATS AVG(memory_usage) | ||
|
|
||
| TS metrics | STATS AVG(LAST_OVER_TIME(memory_usage)) | ||
| ``` | ||
|
|
||
| Calculating the average memory usage across per-time-series averages requires | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| the following query: | ||
|
|
||
| ```esql | ||
| TS metrics | STATS AVG(AVG_OVER_TIME(memory_usage)) | ||
| ``` | ||
| :::: | ||
|
|
||
| Standard (non-time-series) aggregation functions, such as `SUM()`, `AVG()`, | ||
| can be used as outer aggregation functions. Using a time-series aggregation as | ||
| the outer function leads to an error. | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ::::{note} | ||
| If the outer aggregation function is missing, results are grouped by `_tsid` and | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| implicitly expanded to include all dimensions that are used to calculate `_tsid`. | ||
| For instance, the output for the following query will include all dimension | ||
| fields in `metrics` - as opposed to just `hourly` for an equivalent query using | ||
| `FROM` source command: | ||
|
|
||
| ```esql | ||
| TS metrics | STATS RATE(search_requests) BY hourly=TBUCKET(1 hour) | ||
| ``` | ||
|
|
||
| Including fields except from time as grouping attributes is not allowed as it'd | ||
| require an aggregation function to combine per-tsid values. | ||
| :::: | ||
|
|
||
| **Best practices** | ||
|
|
||
| - Avoid mixing aggregation functions on different metrics in the same query, to | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| avoid interference between different time-series. For instance, if one metric | ||
| is missing values for a given `_tsid`, the time-series aggregation function | ||
| may return null for a given combination of dimensions, which may lead to a | ||
| null result for that group if the secondary function returns null on a null | ||
| arg. More so, null metric filtering is more efficient when a query includes | ||
| a single metric. | ||
| - Prefer the `TS` command for aggregations on time-series data. `FROM` is still | ||
| applicable, e.g. to list document contents, but it's not optimized to process | ||
| time-series data efficiently. More so, the `TS` command can't be combined | ||
| with certain operation such as `FORK`, before the `STATS` command is applied. | ||
| That said, once `STATS` is applied, its tabular output can be further | ||
| processed as applicable, in line with regular ES|QL processing. | ||
| - Include a time range filter on `@timestamp`, to prevent scanning | ||
| unnecessarily large data volumes. | ||
|
|
||
| **Syntax** | ||
|
|
||
|
|
@@ -26,6 +134,7 @@ TS index_pattern [METADATA fields] | |
|
|
||
| ```esql | ||
| TS metrics | ||
| | STATS sum(last_over_time(memory_usage)) | ||
| | WHERE @timestamp >= now() - 1 day | ||
| | STATS SUM(AVG_OVER_TIME(memory_usage)) BY host, TBUCKET(1 hour) | ||
| ``` | ||
|
|
||
3 changes: 2 additions & 1 deletion
3
docs/reference/query-languages/esql/_snippets/lists/source-commands.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| - [`FROM`](/reference/query-languages/esql/commands/from.md) | ||
| - [`ROW`](/reference/query-languages/esql/commands/row.md) | ||
| - [`SHOW`](/reference/query-languages/esql/commands/show.md) | ||
| - [`SHOW`](/reference/query-languages/esql/commands/show.md) | ||
| - [`TS`](/reference/query-languages/esql/commands/ts.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| navigation_title: "TS" | ||
| mapped_pages: | ||
| - https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-commands.html#esql-ts | ||
| --- | ||
|
|
||
| # `TS` [esql-ts] | ||
|
|
||
| :::{include} ../_snippets/commands/layout/ts.md | ||
| ::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.