tsds.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. [[tsds]]
  2. == Time series data stream (TSDS)
  3. A time series data stream (TSDS) models timestamped metrics data as one or
  4. more time series.
  5. You can use a TSDS to store metrics data more efficiently. In our benchmarks,
  6. metrics data stored in a TSDS used 70% less disk space than a regular data
  7. stream. The exact impact will vary per data set.
  8. [discrete]
  9. [[when-to-use-tsds]]
  10. === When to use a TSDS
  11. Both a <<data-streams,regular data stream>> and a TSDS can store timestamped
  12. metrics data. Only use a TSDS if you typically add metrics data to {es} in near
  13. real-time and `@timestamp` order.
  14. A TSDS is only intended for metrics data. For other timestamped data, such as
  15. logs or traces, use a <<logs-data-stream,logs data stream>> or regular data stream.
  16. [discrete]
  17. [[differences-from-regular-data-stream]]
  18. === Differences from a regular data stream
  19. A TSDS works like a regular data stream with some key differences:
  20. * The matching index template for a TSDS requires a `data_stream` object with
  21. the <<time-series-mode,`index.mode: time_series`>> option. This option enables
  22. most TSDS-related functionality.
  23. * In addition to a `@timestamp`, each document in a TSDS must contain one or
  24. more <<time-series-dimension,dimension fields>>. The matching index template for
  25. a TSDS must contain mappings for at least one `keyword` dimension.
  26. +
  27. TSDS documents also typically
  28. contain one or more <<time-series-metric,metric fields>>.
  29. * {es} generates a hidden <<tsid,`_tsid`>> metadata field for each document in a
  30. TSDS.
  31. * A TSDS uses <<time-bound-indices,time-bound backing indices>> to store data
  32. from the same time period in the same backing index.
  33. * The matching index template for a TSDS must contain the `index.routing_path`
  34. index setting. A TSDS uses this setting to perform
  35. <<dimension-based-routing,dimension-based routing>>.
  36. * A TSDS uses internal <<index-modules-index-sorting,index sorting>> to order
  37. shard segments by `_tsid` and `@timestamp`.
  38. * TSDS documents only support auto-generated document `_id` values. For TSDS
  39. documents, the document `_id` is a hash of the document's dimensions and
  40. `@timestamp`. A TSDS doesn't support custom document `_id` values.
  41. * A TSDS uses <<synthetic-source,synthetic `_source`>>, and as a result is
  42. subject to some <<synthetic-source-restrictions,restrictions>> and <<synthetic-source-modifications,modifications>> applied to the `_source` field.
  43. NOTE: A time series index can contain fields other than dimensions or metrics.
  44. [discrete]
  45. [[time-series]]
  46. === What is a time series?
  47. A time series is a sequence of observations for a specific entity. Together,
  48. these observations let you track changes to the entity over time. For example, a
  49. time series can track:
  50. * CPU and disk usage for a computer
  51. * The price of a stock
  52. * Temperature and humidity readings from a weather sensor.
  53. .Time series of weather sensor readings plotted as a graph
  54. image::images/data-streams/time-series-chart.svg[align="center"]
  55. In a TSDS, each {es} document represents an observation, or data point, in a
  56. specific time series. Although a TSDS can contain multiple time series, a
  57. document can only belong to one time series. A time series can't span multiple
  58. data streams.
  59. [discrete]
  60. [[time-series-dimension]]
  61. ==== Dimensions
  62. Dimensions are field names and values that, in combination, identify a
  63. document's time series. In most cases, a dimension describes some aspect of the
  64. entity you're measuring. For example, documents related to the same weather
  65. sensor may always have the same `sensor_id` and `location` values.
  66. A TSDS document is uniquely identified by its time series and timestamp, both of
  67. which are used to generate the document `_id`. So, two documents with the same
  68. dimensions and the same timestamp are considered to be duplicates. When you use
  69. the `_bulk` endpoint to add documents to a TSDS, a second document with the same
  70. timestamp and dimensions overwrites the first. When you use the
  71. `PUT /<target>/_create/<_id>` format to add an individual document and a document
  72. with the same `_id` already exists, an error is generated.
  73. You mark a field as a dimension using the boolean `time_series_dimension`
  74. mapping parameter. The following field types support the `time_series_dimension`
  75. parameter:
  76. * <<keyword-field-type,`keyword`>>
  77. * <<ip,`ip`>>
  78. * <<number,`byte`>>
  79. * <<number,`short`>>
  80. * <<number,`integer`>>
  81. * <<number,`long`>>
  82. * <<number,`unsigned_long`>>
  83. * <<boolean,`boolean`>>
  84. For a flattened field, use the `time_series_dimensions` parameter to configure an array of fields as dimensions.
  85. For details refer to <<flattened-params,`flattened`>>.
  86. Dimension definitions can be simplified through <<passthrough-dimensions, pass-through>> fields.
  87. [discrete]
  88. [[time-series-metric]]
  89. ==== Metrics
  90. Metrics are fields that contain numeric measurements, as well as aggregations
  91. and/or downsampling values based off of those measurements. While not required,
  92. documents in a TSDS typically contain one or more metric fields.
  93. Metrics differ from dimensions in that while dimensions generally remain
  94. constant, metrics are expected to change over time, even if rarely or slowly.
  95. To mark a field as a metric, you must specify a metric type using the
  96. `time_series_metric` mapping parameter. The following field types support the
  97. `time_series_metric` parameter:
  98. * <<aggregate-metric-double,`aggregate_metric_double`>>
  99. * <<histogram,`histogram`>>
  100. * All <<number,numeric field types>>
  101. Accepted metric types vary based on the field type:
  102. .Valid values for `time_series_metric`
  103. [%collapsible%open]
  104. ====
  105. // tag::time-series-metric-counter[]
  106. `counter`:: A cumulative metric that only monotonically increases or resets to `0` (zero). For
  107. example, a count of errors or completed tasks.
  108. // end::time-series-metric-counter[]
  109. +
  110. A counter field has additional semantic meaning, because it represents a cumulative counter. This works well with
  111. the `rate` aggregation, since a rate can be derived from a cumulative monotonically increasing counter. However a number
  112. of aggregations (for example `sum`) compute results that don't make sense for a counter field, because of its cumulative nature.
  113. +
  114. Only numeric and `aggregate_metric_double` fields support the `counter` metric type.
  115. NOTE: Due to the cumulative nature of counter fields, the following aggregations are supported and expected to provide meaningful results with the `counter` field: `rate`, `histogram`, `range`, `min`, `max`, `top_metrics` and `variable_width_histogram`. In order to prevent issues with existing integrations and custom dashboards, we also allow the following aggregations, even if the result might be meaningless on counters: `avg`, `box plot`, `cardinality`, `extended stats`, `median absolute deviation`, `percentile ranks`, `percentiles`, `stats`, `sum` and `value count`.
  116. // tag::time-series-metric-gauge[]
  117. `gauge`:: A metric that represents a single numeric that can arbitrarily increase or decrease. For example, a temperature or
  118. available disk space.
  119. // end::time-series-metric-gauge[]
  120. +
  121. Only numeric and `aggregate_metric_double` fields support the `gauge` metric
  122. type.
  123. // tag::time-series-metric-null[]
  124. `null` (Default):: Not a time series metric.
  125. // end::time-series-metric-null[]
  126. ====
  127. [discrete]
  128. [[time-series-mode]]
  129. === Time series mode
  130. The matching index template for a TSDS must contain a `data_stream` object with
  131. the `index_mode: time_series` option. This option ensures the TSDS creates
  132. backing indices with an <<index-mode,`index.mode`>> setting of `time_series`.
  133. This setting enables most TSDS-related functionality in the backing indices.
  134. If you convert an existing data stream to a TSDS, only backing indices created
  135. after the conversion have an `index.mode` of `time_series`. You can't
  136. change the `index.mode` of an existing backing index.
  137. [discrete]
  138. [[tsid]]
  139. ==== `_tsid` metadata field
  140. When you add a document to a TSDS, {es} automatically generates a `_tsid`
  141. metadata field for the document. The `_tsid` is an object containing the
  142. document's dimensions. Documents in the same TSDS with the same `_tsid` are part
  143. of the same time series.
  144. The `_tsid` field is not queryable or updatable. You also can't retrieve a
  145. document's `_tsid` using a <<docs-get,get document>> request. However, you can
  146. use the `_tsid` field in aggregations and retrieve the `_tsid` value in searches
  147. using the <<search-fields-param,`fields` parameter>>.
  148. WARNING: The format of the `_tsid` field shouldn't be relied upon. It may change
  149. from version to version.
  150. [discrete]
  151. [[time-bound-indices]]
  152. ==== Time-bound indices
  153. In a TSDS, each backing index, including the most recent backing index, has a
  154. range of accepted `@timestamp` values. This range is defined by the
  155. <<index-time-series-start-time,`index.time_series.start_time`>> and
  156. <<index-time-series-end-time,`index.time_series.end_time`>> index settings.
  157. When you add a document to a TSDS, {es} adds the document to the appropriate
  158. backing index based on its `@timestamp` value. As a result, a TSDS can add
  159. documents to any TSDS backing index that can receive writes. This applies even
  160. if the index isn't the most recent backing index.
  161. image::images/data-streams/time-bound-indices.svg[align="center"]
  162. TIP: Some {ilm-init} actions mark the source index as read-only, or expect the index
  163. to not be actively written anymore in order to provide good performance. These actions are:
  164. - <<ilm-delete>>
  165. - <<ilm-downsample>>
  166. - <<ilm-forcemerge>>
  167. - <<ilm-readonly>>
  168. - <<ilm-searchable-snapshot>>
  169. - <<ilm-shrink>>
  170. {ilm-cap} will **not** proceed with executing these actions until the upper time-bound
  171. for accepting writes, represented by the <<index-time-series-end-time,`index.time_series.end_time`>>
  172. index setting, has lapsed.
  173. If no backing index can accept a document's `@timestamp` value, {es} rejects the
  174. document.
  175. {es} automatically configures `index.time_series.start_time` and
  176. `index.time_series.end_time` settings as part of the index creation and rollover
  177. process.
  178. [discrete]
  179. [[tsds-look-ahead-time]]
  180. ==== Look-ahead time
  181. Use the <<index-look-ahead-time,`index.look_ahead_time`>> index setting to
  182. configure how far into the future you can add documents to an index. When you
  183. create a new write index for a TSDS, {es} calculates the index's
  184. `index.time_series.end_time` value as:
  185. `now + index.look_ahead_time`
  186. At the time series poll interval (controlled via `time_series.poll_interval` setting),
  187. {es} checks if the write index has met the rollover criteria in its index
  188. lifecycle policy. If not, {es} refreshes the `now` value and updates the write
  189. index's `index.time_series.end_time` to:
  190. `now + index.look_ahead_time + time_series.poll_interval`
  191. This process continues until the write index rolls over. When the index rolls
  192. over, {es} sets a final `index.time_series.end_time` value for the index. This
  193. value borders the `index.time_series.start_time` for the new write index. This
  194. ensures the `@timestamp` ranges for neighboring backing indices always border
  195. but never overlap.
  196. [discrete]
  197. [[tsds-look-back-time]]
  198. ==== Look-back time
  199. Use the <<index-look-back-time,`index.look_back_time`>> index setting to
  200. configure how far in the past you can add documents to an index. When you
  201. create a data stream for a TSDS, {es} calculates the index's
  202. `index.time_series.start_time` value as:
  203. `now - index.look_back_time`
  204. This setting is only used when a data stream gets created and controls
  205. the `index.time_series.start_time` index setting of the first backing index.
  206. Configuring this index setting can be useful to accept documents with `@timestamp`
  207. field values that are older than 2 hours (the `index.look_back_time` default).
  208. [discrete]
  209. [[tsds-accepted-time-range]]
  210. ==== Accepted time range for adding data
  211. A TSDS is designed to ingest current metrics data. When the TSDS is first
  212. created the initial backing index has:
  213. * an `index.time_series.start_time` value set to `now - index.look_back_time`
  214. * an `index.time_series.end_time` value set to `now + index.look_ahead_time`
  215. Only data that falls inside that range can be indexed.
  216. You can use the <<indices-get-data-stream,get data stream API>> to check the
  217. accepted time range for writing to any TSDS.
  218. [discrete]
  219. [[dimension-based-routing]]
  220. ==== Dimension-based routing
  221. Within each TSDS backing index, {es} uses the
  222. <<index-routing-path,`index.routing_path`>> index setting to route documents
  223. with the same dimensions to the same shards.
  224. When you create the matching index template for a TSDS, you must specify one or
  225. more dimensions in the `index.routing_path` setting. Each document in a TSDS
  226. must contain one or more dimensions that match the `index.routing_path` setting.
  227. The `index.routing_path` setting accepts wildcard patterns (for example `dim.*`)
  228. and can dynamically match new fields. However, {es} will reject any mapping
  229. updates that add scripted, runtime, or non-dimension fields that
  230. match the `index.routing_path` value.
  231. <<passthrough-dimensions, Pass-through>> fields may be configured
  232. as dimension containers. In this case, their sub-fields get included to the
  233. routing path automatically.
  234. TSDS documents don't support a custom `_routing` value. Similarly, you can't
  235. require a `_routing` value in mappings for a TSDS.
  236. [discrete]
  237. [[tsds-index-sorting]]
  238. ==== Index sorting
  239. {es} uses <<index-codec,compression algorithms>> to compress repeated values.
  240. This compression works best when repeated values are stored near each other — in
  241. the same index, on the same shard, and side-by-side in the same shard segment.
  242. Most time series data contains repeated values. Dimensions are repeated across
  243. documents in the same time series. The metric values of a time series may also
  244. change slowly over time.
  245. Internally, each TSDS backing index uses <<index-modules-index-sorting,index
  246. sorting>> to order its shard segments by `_tsid` and `@timestamp`. This makes it
  247. more likely that these repeated values are stored near each other for better
  248. compression. A TSDS doesn't support any
  249. <<index-modules-index-sorting,`index.sort.*`>> index settings.
  250. [discrete]
  251. [[tsds-whats-next]]
  252. === What's next?
  253. Now that you know the basics, you're ready to <<set-up-tsds,create a TSDS>> or
  254. <<set-up-tsds,convert an existing data stream to a TSDS>>.
  255. include::set-up-tsds.asciidoc[]
  256. include::tsds-index-settings.asciidoc[]
  257. include::downsampling.asciidoc[]
  258. include::downsampling-ilm.asciidoc[]
  259. include::downsampling-manual.asciidoc[]
  260. include::downsampling-dsl.asciidoc[]
  261. include::tsds-reindex.asciidoc[]