set-up-tsds.asciidoc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. [[set-up-tsds]]
  2. === Set up a time series data stream (TSDS)
  3. ++++
  4. <titleabbrev>Set up a TSDS</titleabbrev>
  5. ++++
  6. To set up a <<tsds,time series data stream (TSDS)>>, follow these steps:
  7. . Check the <<tsds-prereqs,prerequisites>>.
  8. . <<tsds-ilm-policy>>.
  9. . <<create-tsds-index-template>>.
  10. . <<create-tsds>>.
  11. . <<secure-tsds>>.
  12. [discrete]
  13. [[tsds-prereqs]]
  14. ==== Prerequisites
  15. * Before you create a TSDS, you should be familiar with <<data-streams,data
  16. streams>> and <<tsds,TSDS concepts>>.
  17. * To follow this tutorial, you must have the following permissions:
  18. ** <<privileges-list-cluster,Cluster privileges>>: `manage_ilm` and
  19. `manage_index_templates`.
  20. ** <<privileges-list-indices,Index privileges>>: `create_doc` and `create_index`
  21. for any TSDS you create or convert. To roll over a TSDS, you must have the
  22. `manage` privilege.
  23. [discrete]
  24. [[tsds-ilm-policy]]
  25. ==== Create an index lifecycle policy
  26. While optional, we recommend using {ilm-init} to automate the management of your
  27. TSDS's backing indices. {ilm-init} requires an index lifecycle policy.
  28. We recommend you specify a `max_age` criteria for the `rollover` action in the
  29. policy. This ensures the <<time-bound-indices,`@timestamp` ranges>> for the
  30. TSDS's backing indices are consistent. For example, setting a `max_age` of `1d`
  31. for the `rollover` action ensures your backing indices consistently contain one
  32. day's worth of data.
  33. ////
  34. [source,console]
  35. ----
  36. PUT /_snapshot/found-snapshots
  37. {
  38. "type": "fs",
  39. "settings": {
  40. "location": "my_backup_location"
  41. }
  42. }
  43. ----
  44. // TESTSETUP
  45. ////
  46. [source,console]
  47. ----
  48. PUT _ilm/policy/my-weather-sensor-lifecycle-policy
  49. {
  50. "policy": {
  51. "phases": {
  52. "hot": {
  53. "actions": {
  54. "rollover": {
  55. "max_age": "1d",
  56. "max_primary_shard_size": "50gb"
  57. }
  58. }
  59. },
  60. "warm": {
  61. "min_age": "30d",
  62. "actions": {
  63. "shrink": {
  64. "number_of_shards": 1
  65. },
  66. "forcemerge": {
  67. "max_num_segments": 1
  68. }
  69. }
  70. },
  71. "cold": {
  72. "min_age": "60d",
  73. "actions": {
  74. "searchable_snapshot": {
  75. "snapshot_repository": "found-snapshots"
  76. }
  77. }
  78. },
  79. "frozen": {
  80. "min_age": "90d",
  81. "actions": {
  82. "searchable_snapshot": {
  83. "snapshot_repository": "found-snapshots"
  84. }
  85. }
  86. },
  87. "delete": {
  88. "min_age": "735d",
  89. "actions": {
  90. "delete": {}
  91. }
  92. }
  93. }
  94. }
  95. }
  96. ----
  97. [discrete]
  98. [[create-tsds-index-template]]
  99. ==== Create an index template
  100. To setup a TSDS create an index template with the following details:
  101. * One or more index patterns that match the TSDS's name. We recommend
  102. using our {fleet-guide}/data-streams.html#data-streams-naming-scheme[data stream
  103. naming scheme].
  104. * Enable data streams.
  105. * Specify a mapping that defines your dimensions and metrics:
  106. ** One or more <<time-series-dimension,dimension fields>> with a `time_series_dimension` value of `true`.
  107. At least one of these dimensions must be a plain `keyword` field.
  108. ** One or more <<time-series-metric,metric fields>>, marked using the `time_series_metric` mapping parameter.
  109. ** Optional: A `date` or `date_nanos` mapping for the `@timestamp` field. If you don’t specify a mapping,
  110. Elasticsearch maps `@timestamp` as a `date` field with default options.
  111. * Define index settings:
  112. ** Set `index.mode` setting to `time_series`.
  113. ** Your lifecycle policy in the `index.lifecycle.name` index setting.
  114. ** Optional: Other index settings, such as <<dynamic-index-number-of-replicas,`index.number_of_replicas`>>,
  115. for your TSDS's backing indices.
  116. * A priority higher than `200` to avoid collisions with built-in templates.
  117. See <<avoid-index-pattern-collisions>>.
  118. * Optional: Component templates containing your mappings and other index settings.
  119. [source,console]
  120. ----
  121. PUT _index_template/my-weather-sensor-index-template
  122. {
  123. "index_patterns": ["metrics-weather_sensors-*"],
  124. "data_stream": { },
  125. "template": {
  126. "settings": {
  127. "index.mode": "time_series",
  128. "index.lifecycle.name": "my-lifecycle-policy"
  129. },
  130. "mappings": {
  131. "properties": {
  132. "sensor_id": {
  133. "type": "keyword",
  134. "time_series_dimension": true
  135. },
  136. "location": {
  137. "type": "keyword",
  138. "time_series_dimension": true
  139. },
  140. "temperature": {
  141. "type": "half_float",
  142. "time_series_metric": "gauge"
  143. },
  144. "humidity": {
  145. "type": "half_float",
  146. "time_series_metric": "gauge"
  147. },
  148. "@timestamp": {
  149. "type": "date"
  150. }
  151. }
  152. }
  153. },
  154. "priority": 500,
  155. "_meta": {
  156. "description": "Template for my weather sensor data"
  157. }
  158. }
  159. ----
  160. // TEST[continued]
  161. ////
  162. [source,console]
  163. ----
  164. DELETE _data_stream/*
  165. DELETE _index_template/*
  166. DELETE _ilm/policy/my-weather-sensor-lifecycle-policy
  167. ----
  168. // TEST[continued]
  169. ////
  170. [discrete]
  171. [[create-tsds]]
  172. ==== Create the TSDS
  173. <<add-documents-to-a-data-stream,Indexing requests>> add documents to a TSDS.
  174. Documents in a TSDS must include:
  175. * A `@timestamp` field
  176. * One or more dimension fields. At least one dimension must be a `keyword` field
  177. that matches the `index.routing_path` index setting, if specified. If not specified
  178. explicitly, `index.routing_path` is set automatically to whichever mappings have
  179. `time_series_dimension` set to `true`.
  180. To automatically create your TSDS, submit an indexing request that
  181. targets the TSDS's name. This name must match one of your index template's
  182. index patterns.
  183. IMPORTANT: To test the following example, update the timestamps to within three hours of
  184. your current time. Data added to a TSDS must always fall within an
  185. <<tsds-accepted-time-range,accepted time range>>.
  186. [source,console]
  187. ----
  188. PUT metrics-weather_sensors-dev/_bulk
  189. { "create":{ } }
  190. { "@timestamp": "2099-05-06T16:21:15.000Z", "sensor_id": "HAL-000001", "location": "plains", "temperature": 26.7,"humidity": 49.9 }
  191. { "create":{ } }
  192. { "@timestamp": "2099-05-06T16:25:42.000Z", "sensor_id": "SYKENET-000001", "location": "swamp", "temperature": 32.4, "humidity": 88.9 }
  193. POST metrics-weather_sensors-dev/_doc
  194. {
  195. "@timestamp": "2099-05-06T16:21:15.000Z",
  196. "sensor_id": "SYKENET-000001",
  197. "location": "swamp",
  198. "temperature": 32.4,
  199. "humidity": 88.9
  200. }
  201. ----
  202. // TEST[skip: The @timestamp value won't match an accepted range in the TSDS]
  203. You can also manually create the TSDS using the
  204. <<indices-create-data-stream,create data stream API>>. The TSDS's name must
  205. still match one of your template's index patterns.
  206. [source,console]
  207. ----
  208. PUT _data_stream/metrics-weather_sensors-dev
  209. ----
  210. // TEST[setup:tsds_template]
  211. // TEST[teardown:tsds_cleanup]
  212. [discrete]
  213. [[secure-tsds]]
  214. ==== Secure the TSDS
  215. Use <<privileges-list-indices,index privileges>> to control access to a TSDS.
  216. Granting privileges on a TSDS grants the same privileges on its backing indices.
  217. For an example, refer to <<data-stream-privileges>>.
  218. [discrete]
  219. [[convert-existing-data-stream-to-tsds]]
  220. ==== Convert an existing data stream to a TSDS
  221. You can also use the above steps to convert an existing regular data stream to
  222. a TSDS. In this case, you'll want to:
  223. * Edit your existing index lifecycle policy, component templates, and index
  224. templates instead of creating new ones.
  225. * Instead of creating the TSDS, manually roll over its write index. This ensures
  226. the current write index and any new backing indices have an
  227. <<time-series-mode,`index.mode` of `time_series`>>.
  228. +
  229. You can manually roll over the write index using the
  230. <<indices-rollover-index,rollover API>>.
  231. +
  232. [source,console]
  233. ----
  234. POST metrics-weather_sensors-dev/_rollover
  235. ----
  236. // TEST[setup:tsds]
  237. // TEST[teardown:tsds_cleanup]
  238. [discrete]
  239. [[set-up-component-templates]]
  240. ==== A note about component templates and index.mode setting
  241. Configuring a TSDS via an index template that uses component templates is a bit more complicated.
  242. Typically with component templates mappings and settings get scattered across multiple component templates.
  243. When configuring the `index.mode` setting in a component template, the `index.routing_path` setting needs to
  244. be defined in the same component template. Additionally the fields mentioned in the `index.routing_path`
  245. also need to be defined in the same component template with the `time_series_dimension` attribute enabled.
  246. The reasons for this is that each component template needs to be valid on its own and the time series index mode
  247. requires the `index.routing_path` setting. When configuring the `index.mode` setting in an index template, the `index.routing_path` setting is configured automatically. It is derived from
  248. the field mappings with `time_series_dimension` attribute enabled.
  249. [discrete]
  250. [[set-up-tsds-whats-next]]
  251. ==== What's next?
  252. Now that you've set up your TSDS, you can manage and use it like a regular
  253. data stream. For more information, refer to:
  254. * <<use-a-data-stream>>
  255. * <<data-streams-change-mappings-and-settings>>
  256. * <<data-stream-apis,data stream APIs>>