set-up-a-data-stream.asciidoc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. [role="xpack"]
  2. [[set-up-a-data-stream]]
  3. == Set up a data stream
  4. To set up a data stream, follow these steps:
  5. . <<configure-a-data-stream-ilm-policy>>.
  6. . <<create-a-data-stream-template>>.
  7. . <<create-a-data-stream>>.
  8. . <<secure-a-data-stream>>.
  9. You can also <<convert-an-index-alias-to-a-data-stream,convert an existing index
  10. alias to a data stream>>.
  11. [discrete]
  12. [[configure-a-data-stream-ilm-policy]]
  13. === Optional: Configure an {ilm-init} lifecycle policy
  14. While optional, we recommend you configure an <<set-up-lifecycle-policy,{ilm}
  15. ({ilm-init}) policy>> to automate the management of your data stream's backing
  16. indices.
  17. In {kib}, open the menu and go to *Stack Management > Index Lifecycle Policies*.
  18. Click *Index Lifecycle Policies*.
  19. [role="screenshot"]
  20. image::images/ilm/create-policy.png[Index Lifecycle Policies page]
  21. [%collapsible]
  22. .API example
  23. ====
  24. Use the <<ilm-put-lifecycle,create lifecycle policy API>> to configure a policy:
  25. [source,console]
  26. ----
  27. PUT /_ilm/policy/my-data-stream-policy
  28. {
  29. "policy": {
  30. "phases": {
  31. "hot": {
  32. "actions": {
  33. "rollover": {
  34. "max_size": "25GB"
  35. }
  36. }
  37. },
  38. "delete": {
  39. "min_age": "30d",
  40. "actions": {
  41. "delete": {}
  42. }
  43. }
  44. }
  45. }
  46. }
  47. ----
  48. ====
  49. [discrete]
  50. [[create-a-data-stream-template]]
  51. === Create an index template
  52. . In {kib}, open the menu and go to *Stack Management > Index Management*.
  53. . In the *Index Templates* tab, click *Create template*.
  54. . In the Create template wizard, use the *Data stream* toggle to indicate the
  55. template is used for data streams.
  56. . Use the wizard to finish defining your template. Specify:
  57. * One or more index patterns that match the data stream's name. +
  58. include::{es-repo-dir}/indices/create-data-stream.asciidoc[tag=data-stream-name]
  59. * Mappings and settings for the stream's backing indices.
  60. * A priority for the index template
  61. +
  62. include::{es-repo-dir}/indices/index-templates.asciidoc[tag=built-in-index-templates]
  63. [[elastic-data-stream-naming-scheme]]
  64. .The Elastic data stream naming scheme
  65. ****
  66. The {agent} uses the Elastic data stream naming scheme to name its data streams.
  67. To help you organize your data consistently and avoid naming collisions, we
  68. recommend you also use the Elastic naming scheme for your other data streams.
  69. The naming scheme splits data into different data streams based on the following
  70. components. Each component corresponds to a
  71. <<constant-keyword-field-type,constant keyword>> field defined in the
  72. {ecs-ref}[Elastic Common Schema (ECS)].
  73. `type`::
  74. Generic type describing the data, such as `logs`, `metrics`, or `synthetics`.
  75. Corresponds to the `data_stream.type` field.
  76. `dataset`::
  77. Describes the ingested data and its structure. Corresponds to the
  78. `data_stream.dataset` field. Defaults to `generic`.
  79. `namespace`::
  80. User-configurable arbitrary grouping. Corresponds to the `data_stream.dataset`
  81. field. Defaults to `default`.
  82. The naming scheme separates these components with a `-` character:
  83. ```
  84. <type>-<dataset>-<namespace>
  85. ```
  86. For example, the {agent} uses the `logs-nginx.access-production` data
  87. stream to store data with a type of `logs`, a dataset of `nginx.access`, and a
  88. namespace of `production`. If you use the {agent} to ingest a log file, it
  89. stores the data in the `logs-generic-default` data stream.
  90. For more information about the naming scheme and its benefits, see our
  91. https://www.elastic.co/blog/an-introduction-to-the-elastic-data-stream-naming-scheme[An
  92. introduction to the Elastic data stream naming scheme] blog post.
  93. ****
  94. include::{es-repo-dir}/data-streams/data-streams.asciidoc[tag=timestamp-reqs]
  95. If using {ilm-init}, specify your lifecycle policy in the `index.lifecycle.name`
  96. setting.
  97. TIP: Carefully consider your template's mappings and settings. Later changes may
  98. require reindexing. See <<data-streams-change-mappings-and-settings>>.
  99. [role="screenshot"]
  100. image::images/data-streams/create-index-template.png[Create template page]
  101. [%collapsible]
  102. .API example
  103. ====
  104. Use the <<indices-put-template,put index template API>> to create an index
  105. template. The template must include a `data_stream` object, indicating
  106. it's used for data streams.
  107. [source,console]
  108. ----
  109. PUT /_index_template/my-data-stream-template
  110. {
  111. "index_patterns": [ "my-data-stream*" ],
  112. "data_stream": { },
  113. "priority": 200,
  114. "template": {
  115. "settings": {
  116. "index.lifecycle.name": "my-data-stream-policy"
  117. }
  118. }
  119. }
  120. ----
  121. // TEST[continued]
  122. ====
  123. [discrete]
  124. [[create-a-data-stream]]
  125. === Create the data stream
  126. To automatically create the data stream, submit an
  127. <<add-documents-to-a-data-stream,indexing request>> to the stream. The stream's
  128. name must match one of your template's index patterns.
  129. [source,console]
  130. ----
  131. POST /my-data-stream/_doc/
  132. {
  133. "@timestamp": "2099-03-07T11:04:05.000Z",
  134. "user": {
  135. "id": "vlb44hny"
  136. },
  137. "message": "Login attempt failed"
  138. }
  139. ----
  140. // TEST[continued]
  141. You can also use the <<indices-create-data-stream,create data stream API>> to
  142. manually create the data stream. The stream's name must match one of your
  143. template's index patterns.
  144. [source,console]
  145. ----
  146. PUT /_data_stream/my-data-stream
  147. ----
  148. // TEST[continued]
  149. // TEST[s/my-data-stream/my-data-stream-alt/]
  150. When you create a data stream, {es} automatically creates a backing index for
  151. the stream. This index also acts as the stream's first write index.
  152. [discrete]
  153. [[convert-an-index-alias-to-a-data-stream]]
  154. === Convert an index alias to a data stream
  155. Prior to {es} 7.9, you would typically use an <<indices-aliases,index alias>>
  156. with a write index to manage time series data. Data streams replace most of
  157. this functionality and usually require less maintenance.
  158. To convert an index alias with a write index to a new data stream with the same
  159. name, use the <<indices-migrate-to-data-stream,migrate to data stream API>>.
  160. During conversion, the alias’s indices become hidden backing indices for the
  161. stream. The alias’s write index becomes the stream’s write index. Note the data
  162. stream still requires a matching <<create-a-data-stream-template,index
  163. template>>.
  164. ////
  165. [source,console]
  166. ----
  167. POST idx1/_doc/
  168. {
  169. "message" : "testing",
  170. "@timestamp" : "2099-01-01"
  171. }
  172. POST idx2/_doc/
  173. {
  174. "message" : "testing2",
  175. "@timestamp" : "2099-01-01"
  176. }
  177. POST /_aliases
  178. {
  179. "actions": [
  180. {
  181. "add": {
  182. "index": "idx1",
  183. "alias": "my-time-series-data",
  184. "is_write_index": true
  185. }
  186. },
  187. {
  188. "add": {
  189. "index": "idx2",
  190. "alias": "my-time-series-data"
  191. }
  192. }
  193. ]
  194. }
  195. PUT /_index_template/template
  196. {
  197. "index_patterns": ["my-time-series-data"],
  198. "data_stream": { }
  199. }
  200. ----
  201. // TEST[continued]
  202. ////
  203. [source,console]
  204. ----
  205. POST /_data_stream/_migrate/my-time-series-data
  206. ----
  207. // TEST[continued]
  208. [discrete]
  209. [[secure-a-data-stream]]
  210. === Secure the data stream
  211. To control access to the data stream and its
  212. data, use <<data-stream-privileges,{es}'s {security-features}>>.
  213. [discrete]
  214. [[get-info-about-a-data-stream]]
  215. === Get information about a data stream
  216. In {kib}, open the menu and go to *Stack Management > Index Management*. In the
  217. *Data Streams* tab, click the data stream's name.
  218. [role="screenshot"]
  219. image::images/data-streams/data-streams-list.png[Data Streams tab]
  220. [%collapsible]
  221. .API example
  222. ====
  223. Use the <<indices-get-data-stream,get data stream API>> to retrieve information
  224. about one or more data streams:
  225. ////
  226. [source,console]
  227. ----
  228. POST /my-data-stream/_rollover/
  229. ----
  230. // TEST[continued]
  231. ////
  232. [source,console]
  233. ----
  234. GET /_data_stream/my-data-stream
  235. ----
  236. // TEST[continued]
  237. ====
  238. [discrete]
  239. [[delete-a-data-stream]]
  240. === Delete a data stream
  241. To delete a data stream and its backing indices, open the {kib} menu and go to
  242. *Stack Management > Index Management*. In the *Data Streams* tab, click the
  243. trash icon. The trash icon only displays if you have the `delete_index`
  244. <<security-privileges, security privilege>> for the data stream.
  245. [role="screenshot"]
  246. image::images/data-streams/data-streams-no-delete.png[Data Streams tab]
  247. [%collapsible]
  248. .API example
  249. ====
  250. Use the <<indices-delete-data-stream,delete data stream API>> to delete a data
  251. stream and its backing indices:
  252. [source,console]
  253. ----
  254. DELETE /_data_stream/my-data-stream
  255. ----
  256. // TEST[continued]
  257. ====
  258. ////
  259. [source,console]
  260. ----
  261. DELETE /_data_stream/*
  262. DELETE /_index_template/*
  263. DELETE /_ilm/policy/my-data-stream-policy
  264. ----
  265. // TEST[continued]
  266. ////