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

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