| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 | [[downsampling]]/////[source,console]--------------------------------------------------DELETE _ilm/policy/my_policy--------------------------------------------------// TEST// TEARDOWN/////=== Downsampling a time series data streamDownsampling provides a method to reduce the footprint of your <<tsds,timeseries data>> by storing it at reduced granularity.Metrics solutions collect large amounts of time series data that grow over time.As that data ages, it becomes less relevant to the current state of the system.The downsampling process rolls up documents within a fixed time interval into asingle summary document. Each summary document includes statisticalrepresentations of the original data: the `min`, `max`, `sum`, `value_count`,and `average` for each metric. Data stream <<time-series-dimension,time seriesdimensions>> are stored unchanged.Downsampling, in effect, lets you to trade data resolution and precision forstorage size. You can include it in an <<index-lifecycle-management,{ilm}({ilm-init})>> policy to automatically manage the volume and associated cost ofyour metrics data at it ages.Check the following sections to learn more:* <<how-downsampling-works>>* <<running-downsampling>>* <<querying-downsampled-indices>>* <<downsampling-restrictions>>* <<try-out-downsampling>>[discrete][[how-downsampling-works]]=== How it worksA <<time-series,time series>> is a sequence of observations taken over time fora specific entity. The observed samples can be represented as a continuousfunction, where the time series dimensions remain constant and the time seriesmetrics change over time.//.Sampling a continuous functionimage::images/data-streams/time-series-function.png[align="center"]In an Elasticsearch index, a single document is created for each timestamp,containing the immutable time series dimensions, together with the metrics namesand the changing metrics values. For a single timestamp, several time seriesdimensions and metrics may be stored.//.Metric anatomyimage::images/data-streams/time-series-metric-anatomy.png[align="center"]For your most current and relevant data, the metrics series typically has a lowsampling time interval, so it's optimized for queries that require a high dataresolution..Original metrics seriesimage::images/data-streams/time-series-original.png[align="center"]Downsampling works on older, less frequently accessed data by replacing theoriginal time series with both a data stream of a higher sampling interval andstatistical representations of that data. Where the original metrics samples mayhave been taken, for example, every ten seconds, as the data ages you may chooseto reduce the sample granularity to hourly or daily. You may choose to reducethe granularity of `cold` archival data to monthly or less..Downsampled metrics seriesimage::images/data-streams/time-series-downsampled.png[align="center"][discrete][[running-downsampling]]=== Running downsampling on time series dataTo downsample a time series index, use the<<indices-downsample-data-stream,Downsample API>> and set `fixed_interval` tothe level of granularity that you'd like:include::../indices/downsample-data-stream.asciidoc[tag=downsample-example]To downsample time series data as part of ILM, include a<<ilm-downsample,Downsample action>> in your ILM policy and set `fixed_interval`to the level of granularity that you'd like:[source,console]----PUT _ilm/policy/my_policy{  "policy": {    "phases": {      "warm": {        "actions": {          "downsample" : {            "fixed_interval": "1h"          }        }      }    }  }}----[discrete][[querying-downsampled-indices]]=== Querying downsampled indicesYou can use the <<search-search,`_search`>> and <<async-search,`_async_search`>>endpoints to query a downsampled index. Multiple raw data and downsampledindices can be queried in a single request, and a single request can includedownsampled indices at different granularities (different bucket timespan). Thatis, you can query data streams that contain downsampled indices with multipledownsampling intervals (for example, `15m`, `1h`, `1d`).The result of a time based histogram aggregation is in a uniform bucket size andeach downsampled index returns data ignoring the downsampling time interval. Forexample, if you run a `date_histogram` aggregation with `"fixed_interval": "1m"`on a downsampled index that has been downsampled at an hourly resolution(`"fixed_interval": "1h"`), the query returns one bucket with all of the data atminute 0, then 59 empty buckets, and then a bucket with data again for the nexthour.[discrete][[querying-downsampled-indices-notes]]==== Notes on downsample queriesThere are a few things to note about querying downsampled indices:* When you run queries in {kib} and through Elastic solutions, a normalresponse is returned without notification that some of the queried indices aredownsampled.* For<<search-aggregations-bucket-datehistogram-aggregation,date histogram aggregations>>,only `fixed_intervals` (and not calendar-aware intervals) are supported.* Timezone support comes with caveats:** Date histograms at intervals that are multiples of an hour are based onvalues generated at UTC. This works well for timezones that are on the hour, e.g.+5:00 or -3:00, but requires offsetting the reported time buckets, e.g.`2020-01-01T10:30:00.000` instead of `2020-03-07T10:00:00.000` fortimezone +5:30 (India), if downsampling aggregates values per hour. In this case,the results include the field `downsampled_results_offset: true`, to indicate thatthe time buckets are shifted. This can be avoided if a downsampling interval of 15minutes is used, as it allows properly calculating hourly values for the shiftedbuckets.** Date histograms at intervals that are multiples of a day are similarlyaffected, in case downsampling aggregates values per day. In this case, thebeginning of each day is always calculated at UTC when generated the downsampledvalues, so the time buckets need to be shifted, e.g. reported as`2020-03-07T19:00:00.000` instead of `2020-03-07T00:00:00.000` for timezone `America/New_York`.The field `downsampled_results_offset: true` is added in this case too.** Daylight savings and similar peculiarities around timezones affectreported results, as <<datehistogram-aggregation-time-zone,documented>>for date histogram aggregation. Besides, downsampling at daily intervalhinders tracking any information related to daylight savings changes.[discrete][[downsampling-restrictions]]=== Restrictions and limitationsThe following restrictions and limitations apply for downsampling:* Only indices in a <<tsds,time series data stream>> are supported.* Data is downsampled based on the time dimension only. All other dimensions arecopied to the new index without any modification.* Within a data stream, a downsampled index replaces the original index and theoriginal index is deleted. Only one index can exist for a given time period.* A source index must be in read-only mode for the downsampling process tosucceed. Check the <<downsampling-manual,Run downsampling manually>> example fordetails.* Downsampling data for the same period many times (downsampling of adownsampled index) is supported. The downsampling interval must be a multiple ofthe interval of the downsampled index.* Downsampling is provided as an ILM action. See <<ilm-downsample,Downsample>>.* The new, downsampled index is created on the data tier of the original indexand it inherits its settings (for example, the number of shards and replicas).* The numeric `gauge` and `counter` <<mapping-field-meta,metric types>> aresupported.* The downsampling configuration is extracted from the time series data stream<<create-tsds-index-template,index mapping>>. The only additionalrequired setting is the downsampling `fixed_interval`.[discrete][[try-out-downsampling]]=== Try it outTo take downsampling for a test run, try our example of<<downsampling-manual,running downsampling manually>>.Downsampling can easily be added to your ILM policy. To learn how, try our<<downsampling-ilm,Run downsampling with ILM>> example.
 |