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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. ****
  91. include::{es-repo-dir}/data-streams/data-streams.asciidoc[tag=timestamp-reqs]
  92. If using {ilm-init}, specify your lifecycle policy in the `index.lifecycle.name`
  93. setting.
  94. TIP: Carefully consider your template's mappings and settings. Later changes may
  95. require reindexing. See <<data-streams-change-mappings-and-settings>>.
  96. [role="screenshot"]
  97. image::images/data-streams/create-index-template.png[Create template page]
  98. [%collapsible]
  99. .API example
  100. ====
  101. Use the <<indices-put-template,put index template API>> to create an index
  102. template. The template must include a `data_stream` object, indicating
  103. it's used for data streams.
  104. [source,console]
  105. ----
  106. PUT /_index_template/my-data-stream-template
  107. {
  108. "index_patterns": [ "my-data-stream*" ],
  109. "data_stream": { },
  110. "priority": 200,
  111. "template": {
  112. "settings": {
  113. "index.lifecycle.name": "my-data-stream-policy"
  114. }
  115. }
  116. }
  117. ----
  118. // TEST[continued]
  119. ====
  120. [discrete]
  121. [[create-a-data-stream]]
  122. === Create the data stream
  123. To automatically create the data stream, submit an
  124. <<add-documents-to-a-data-stream,indexing request>> to the stream. The stream's
  125. name must match one of your template's index patterns.
  126. [source,console]
  127. ----
  128. POST /my-data-stream/_doc/
  129. {
  130. "@timestamp": "2099-03-07T11:04:05.000Z",
  131. "user": {
  132. "id": "vlb44hny"
  133. },
  134. "message": "Login attempt failed"
  135. }
  136. ----
  137. // TEST[continued]
  138. You can also use the <<indices-create-data-stream,create data stream API>> to
  139. manually create the data stream. The stream's name must match one of your
  140. template's index patterns.
  141. [source,console]
  142. ----
  143. PUT /_data_stream/my-data-stream
  144. ----
  145. // TEST[continued]
  146. // TEST[s/my-data-stream/my-data-stream-alt/]
  147. When you create a data stream, {es} automatically creates a backing index for
  148. the stream. This index also acts as the stream's first write index.
  149. [discrete]
  150. [[convert-an-index-alias-to-a-data-stream]]
  151. === Convert an index alias to a data stream
  152. Prior to {es} 7.9, you would typically use an <<indices-aliases,index alias>>
  153. with a write index to manage time series data. Data streams replace most of
  154. this functionality and usually require less maintenance.
  155. To convert an index alias with a write index to a new data stream with the same
  156. name, use the <<indices-migrate-to-data-stream,migrate to data stream API>>.
  157. During conversion, the alias’s indices become hidden backing indices for the
  158. stream. The alias’s write index becomes the stream’s write index. Note the data
  159. stream still requires a matching <<create-a-data-stream-template,index
  160. template>>.
  161. ////
  162. [source,console]
  163. ----
  164. POST idx1/_doc/
  165. {
  166. "message" : "testing",
  167. "@timestamp" : "2099-01-01"
  168. }
  169. POST idx2/_doc/
  170. {
  171. "message" : "testing2",
  172. "@timestamp" : "2099-01-01"
  173. }
  174. POST /_aliases
  175. {
  176. "actions": [
  177. {
  178. "add": {
  179. "index": "idx1",
  180. "alias": "my-time-series-data",
  181. "is_write_index": true
  182. }
  183. },
  184. {
  185. "add": {
  186. "index": "idx2",
  187. "alias": "my-time-series-data"
  188. }
  189. }
  190. ]
  191. }
  192. PUT /_index_template/template
  193. {
  194. "index_patterns": ["my-time-series-data"],
  195. "data_stream": { }
  196. }
  197. ----
  198. // TEST[continued]
  199. ////
  200. [source,console]
  201. ----
  202. POST /_data_stream/_migrate/my-time-series-data
  203. ----
  204. // TEST[continued]
  205. [discrete]
  206. [[secure-a-data-stream]]
  207. === Secure the data stream
  208. To control access to the data stream and its
  209. data, use <<data-stream-privileges,{es}'s {security-features}>>.
  210. [discrete]
  211. [[get-info-about-a-data-stream]]
  212. === Get information about a data stream
  213. In {kib}, open the menu and go to *Stack Management > Index Management*. In the
  214. *Data Streams* tab, click the data stream's name.
  215. [role="screenshot"]
  216. image::images/data-streams/data-streams-list.png[Data Streams tab]
  217. [%collapsible]
  218. .API example
  219. ====
  220. Use the <<indices-get-data-stream,get data stream API>> to retrieve information
  221. about one or more data streams:
  222. ////
  223. [source,console]
  224. ----
  225. POST /my-data-stream/_rollover/
  226. ----
  227. // TEST[continued]
  228. ////
  229. [source,console]
  230. ----
  231. GET /_data_stream/my-data-stream
  232. ----
  233. // TEST[continued]
  234. ====
  235. [discrete]
  236. [[delete-a-data-stream]]
  237. === Delete a data stream
  238. To delete a data stream and its backing indices, open the {kib} menu and go to
  239. *Stack Management > Index Management*. In the *Data Streams* tab, click the
  240. trash icon. The trash icon only displays if you have the `delete_index`
  241. <<security-privileges, security privilege>> for the data stream.
  242. [role="screenshot"]
  243. image::images/data-streams/data-streams-no-delete.png[Data Streams tab]
  244. [%collapsible]
  245. .API example
  246. ====
  247. Use the <<indices-delete-data-stream,delete data stream API>> to delete a data
  248. stream and its backing indices:
  249. [source,console]
  250. ----
  251. DELETE /_data_stream/my-data-stream
  252. ----
  253. // TEST[continued]
  254. ====
  255. ////
  256. [source,console]
  257. ----
  258. DELETE /_data_stream/*
  259. DELETE /_index_template/*
  260. DELETE /_ilm/policy/my-data-stream-policy
  261. ----
  262. // TEST[continued]
  263. ////