tsds.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. [[tsds]]
  2. == Time series data stream (TSDS)
  3. preview::[]
  4. A time series data stream (TSDS) models timestamped metrics data as one or
  5. more time series.
  6. // TODO: Replace XX% with actual percentage
  7. You can use a TSDS to store metrics data more efficiently. In our benchmarks,
  8. metrics data stored in a TSDS used 44% less disk space than a regular data
  9. stream.
  10. [discrete]
  11. [[when-to-use-tsds]]
  12. === When to use a TSDS
  13. Both a <<data-streams,regular data stream>> and a TSDS can store timestamped
  14. metrics data. Only use a TSDS if you typically add metrics data to {es} in near
  15. real-time and `@timestamp` order.
  16. A TSDS is only intended for metrics data. For other timestamped data, such as
  17. logs or traces, use a regular data stream.
  18. [discrete]
  19. [[differences-from-regular-data-stream]]
  20. === Differences from a regular data stream
  21. A TSDS works like a regular data stream with some key differences:
  22. * The matching index template for a TSDS requires a `data_stream` object with
  23. the <<time-series-mode,`index_mode: time_series`>> option. This option enables
  24. most TSDS-related functionality.
  25. * In addition to a `@timestamp`, each document in a TSDS must contain one or
  26. more <<time-series-dimension,dimension fields>>. The matching index template for
  27. a TSDS must contain mappings for at least one `keyword` dimension.
  28. +
  29. TSDS documents also typically
  30. contain one or more <<time-series-metric,metric fields>>.
  31. * {es} generates a hidden <<tsid,`_tsid`>> metadata field for each document in a
  32. TSDS.
  33. * A TSDS uses <<time-bound-indices,time-bound backing indices>> to store data
  34. from the same time period in the same backing index.
  35. * The matching index template for a TSDS must contain the `index.routing_path`
  36. index setting. A TSDS uses this setting to perform
  37. <<dimension-based-routing,dimension-based routing>>.
  38. * A TSDS uses internal <<index-modules-index-sorting,index sorting>> to order
  39. shard segments by `_tsid` and `@timestamp`.
  40. * TSDS documents only support auto-generated document `_id` values. For TSDS
  41. documents, the document `_id` is a hash of the document's dimensions and
  42. `@timestamp`. A TSDS doesn't support custom document `_id` values.
  43. [discrete]
  44. [[time-series]]
  45. === What is a time series?
  46. A time series is a sequence of observations for a specific entity. Together,
  47. these observations let you track changes to the entity over time. For example, a
  48. time series can track:
  49. * CPU and disk usage for a computer
  50. * The price of a stock
  51. * Temperature and humidity readings from a weather sensor.
  52. .Time series of weather sensor readings plotted as a graph
  53. image::images/data-streams/time-series-chart.svg[align="center"]
  54. In a TSDS, each {es} document represents an observation, or data point, in a
  55. specific time series. Although a TSDS can contain multiple time series, a
  56. document can only belong to one time series. A time series can't span multiple
  57. data streams.
  58. [discrete]
  59. [[time-series-dimension]]
  60. ==== Dimensions
  61. Dimensions are field names and values that, in combination, identify a
  62. document's time series. In most cases, a dimension describes some aspect of the
  63. entity you're measuring. For example, documents related to the same weather
  64. sensor may always have the same `sensor_id` and `location` values.
  65. A TSDS document is uniquely identified by its time series and timestamp, both of
  66. which are used to generate the document `_id`. So, two documents with the same
  67. dimensions and the same timestamp are considered to be duplicates. When you use
  68. the `_bulk` endpoint to add documents to a TSDS, a second document with the same
  69. timestamp and dimensions overwrites the first. When you use the
  70. `PUT /<target>/_create/<_id>` format to add an individual document and a document
  71. with the same `_id` already exists, an error is generated.
  72. You mark a field as a dimension using the boolean `time_series_dimension`
  73. mapping parameter. The following field types support the `time_series_dimension`
  74. parameter:
  75. * <<keyword-field-type,`keyword`>>
  76. * <<ip,`ip`>>
  77. * <<number,`byte`>>
  78. * <<number,`short`>>
  79. * <<number,`integer`>>
  80. * <<number,`long`>>
  81. * <<number,`unsigned_long`>>
  82. [[dimension-limits]]
  83. .Dimension limits
  84. ****
  85. In a TSDS, {es} uses dimensions to
  86. generate the document `_id` and <<tsid,`_tsid`>> values. The resulting `_id` is
  87. always a short encoded hash. To prevent the `_tsid` value from being overly
  88. large, {es} limits the number of dimensions for an index using the
  89. <<index-mapping-dimension-fields-limit,`index.mapping.dimension_fields.limit`>>
  90. index setting. While you can increase this limit, the resulting document `_tsid`
  91. value can't exceed 32KB.
  92. ****
  93. [discrete]
  94. [[time-series-metric]]
  95. ==== Metrics
  96. Metrics are fields that contain numeric measurements, as well as aggregations
  97. and/or downsampling values based off of those measurements. While not required,
  98. documents in a TSDS typically contain one or more metric fields.
  99. Metrics differ from dimensions in that while dimensions generally remain
  100. constant, metrics are expected to change over time, even if rarely or slowly.
  101. To mark a field as a metric, you must specify a metric type using the
  102. `time_series_metric` mapping parameter. The following field types support the
  103. `time_series_metric` parameter:
  104. * <<aggregate-metric-double,`aggregate_metric_double`>>
  105. * <<histogram,`histogram`>>
  106. * All <<number,numeric field types>>
  107. Accepted metric types vary based on the field type:
  108. .Valid values for `time_series_metric`
  109. [%collapsible%open]
  110. ====
  111. // tag::time-series-metric-counter[]
  112. `counter`:: A number that only increases or resets to `0` (zero). For
  113. example, a count of errors or completed tasks.
  114. // end::time-series-metric-counter[]
  115. +
  116. Only numeric and `aggregate_metric_double` fields support the `counter` metric
  117. type.
  118. // tag::time-series-metric-gauge[]
  119. `gauge`:: A number that can increase or decrease. For example, a temperature or
  120. available disk space.
  121. // end::time-series-metric-gauge[]
  122. +
  123. Only numeric and `aggregate_metric_double` fields support the `gauge` metric
  124. type.
  125. // tag::time-series-metric-null[]
  126. `null` (Default):: Not a time series metric.
  127. // end::time-series-metric-null[]
  128. ====
  129. [discrete]
  130. [[time-series-mode]]
  131. === Time series mode
  132. The matching index template for a TSDS must contain a `data_stream` object with
  133. the `index_mode: time_series` option. This option ensures the TSDS creates
  134. backing indices with an <<index-mode,`index.mode`>> setting of `time_series`.
  135. This setting enables most TSDS-related functionality in the backing indices.
  136. If you convert an existing data stream to a TSDS, only backing indices created
  137. after the conversion have an `index.mode` of `time_series`. You can't
  138. change the `index.mode` of an existing backing index.
  139. [discrete]
  140. [[tsid]]
  141. ==== `_tsid` metadata field
  142. When you add a document to a TSDS, {es} automatically generates a `_tsid`
  143. metadata field for the document. The `_tsid` is an object containing the
  144. document's dimensions. Documents in the same TSDS with the same `_tsid` are part
  145. of the same time series.
  146. The `_tsid` field is not queryable or updatable. You also can't retrieve a
  147. document's `_tsid` using a <<docs-get,get document>> request. However, you can
  148. use the `_tsid` field in aggregations and retrieve the `_tsid` value in searches
  149. using the <<search-fields-param,`fields` parameter>>.
  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, such as <<ilm-forcemerge,`forcemerge`>>,
  163. <<ilm-shrink,`shrink`>>, and <<ilm-searchable-snapshot,`searchable_snapshot`>>,
  164. make a backing index read-only. You cannot add documents to read-only indices.
  165. Keep this in mind when defining the index lifecycle policy for your TSDS.
  166. If no backing index can accept a document's `@timestamp` value, {es} rejects the
  167. document.
  168. {es} automatically configures `index.time_series.start_time` and
  169. `index.time_series.end_time` settings as part of the index creation and rollover
  170. process.
  171. [discrete]
  172. [[tsds-look-ahead-time]]
  173. ==== Look-ahead time
  174. Use the <<index-look-ahead-time,`index.look_ahead_time`>> index setting to
  175. configure how far into the future you can add documents to an index. When you
  176. create a new write index for a TSDS, {es} calculates the index's
  177. `index.time_series.end_time` value as:
  178. `now + index.look_ahead_time`
  179. At the time series poll interval (controlled via `time_series.poll_interval` setting),
  180. {es} checks if the write index has met the rollover criteria in its index
  181. lifecycle policy. If not, {es} refreshes the `now` value and updates the write
  182. index's `index.time_series.end_time` to:
  183. `now + index.look_ahead_time + time_series.poll_interval`
  184. This process continues until the write index rolls over. When the index rolls
  185. over, {es} sets a final `index.time_series.end_time` value for the index. This
  186. value borders the `index.time_series.start_time` for the new write index. This
  187. ensures the `@timestamp` ranges for neighboring backing indices always border
  188. but never overlap.
  189. [discrete]
  190. [[tsds-accepted-time-range]]
  191. ==== Accepted time range for adding data
  192. A TSDS is designed to ingest current metrics data. When the TSDS is first
  193. created the initial backing index has:
  194. * an `index.time_series.start_time` value set to `now - index.look_ahead_time`
  195. * an `index.time_series.end_time` value set to `now + index.look_ahead_time`
  196. Only data that falls inside that range can be indexed.
  197. In our <<tsds-create-index-settings-component-template,TSDS example>>,
  198. `index.look_ahead_time` is set to three hours, so only documents with a
  199. `@timestamp` value that is within three hours previous or subsequent to the
  200. present time are accepted for indexing.
  201. You can use the <<indices-get-data-stream,get data stream API>> to check the
  202. accepted time range for writing to any TSDS.
  203. [discrete]
  204. [[dimension-based-routing]]
  205. ==== Dimension-based routing
  206. Within each TSDS backing index, {es} uses the
  207. <<index-routing-path,`index.routing_path`>> index setting to route documents
  208. with the same dimensions to the same shards.
  209. When you create the matching index template for a TSDS, you must specify one or
  210. more dimensions in the `index.routing_path` setting. Each document in a TSDS
  211. must contain one or more dimensions that match the `index.routing_path` setting.
  212. Dimensions in the `index.routing_path` setting must be plain `keyword` fields.
  213. The `index.routing_path` setting accepts wildcard patterns (for example `dim.*`)
  214. and can dynamically match new fields. However, {es} will reject any mapping
  215. updates that add scripted, runtime, or non-dimension, non-`keyword` fields that
  216. match the `index.routing_path` value.
  217. TSDS documents don't support a custom `_routing` value. Similarly, you can't
  218. require a `_routing` value in mappings for a TSDS.
  219. [discrete]
  220. [[tsds-index-sorting]]
  221. ==== Index sorting
  222. {es} uses <<index-codec,compression algorithms>> to compress repeated values.
  223. This compression works best when repeated values are stored near each other — in
  224. the same index, on the same shard, and side-by-side in the same shard segment.
  225. Most time series data contains repeated values. Dimensions are repeated across
  226. documents in the same time series. The metric values of a time series may also
  227. change slowly over time.
  228. Internally, each TSDS backing index uses <<index-modules-index-sorting,index
  229. sorting>> to order its shard segments by `_tsid` and `@timestamp`. This makes it
  230. more likely that these repeated values are stored near each other for better
  231. compression. A TSDS doesn't support any
  232. <<index-modules-index-sorting,`index.sort.*`>> index settings.
  233. [discrete]
  234. [[tsds-whats-next]]
  235. === What's next?
  236. Now that you know the basics, you're ready to <<set-up-tsds,create a TSDS>> or
  237. <<set-up-tsds,convert an existing data stream to a TSDS>>.
  238. include::set-up-tsds.asciidoc[]
  239. include::tsds-index-settings.asciidoc[]
  240. include::downsampling.asciidoc[]
  241. include::downsampling-manual.asciidoc[]
  242. include::downsampling-ilm.asciidoc[]