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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. [discrete]
  10. [[configure-a-data-stream-ilm-policy]]
  11. === Optional: Configure an {ilm-init} lifecycle policy
  12. While optional, we recommend you configure an <<set-up-lifecycle-policy,{ilm}
  13. ({ilm-init}) policy>> to automate the management of your data stream's backing
  14. indices.
  15. In {kib}, open the menu and go to *Stack Management > Index Lifecycle Policies*.
  16. Click *Index Lifecycle Policies*.
  17. [role="screenshot"]
  18. image::images/ilm/create-policy.png[Index Lifecycle Policies page]
  19. [%collapsible]
  20. .API example
  21. ====
  22. Use the <<ilm-put-lifecycle,create lifecycle policy API>> to configure a policy:
  23. [source,console]
  24. ----
  25. PUT /_ilm/policy/my-data-stream-policy
  26. {
  27. "policy": {
  28. "phases": {
  29. "hot": {
  30. "actions": {
  31. "rollover": {
  32. "max_size": "25GB"
  33. }
  34. }
  35. },
  36. "delete": {
  37. "min_age": "30d",
  38. "actions": {
  39. "delete": {}
  40. }
  41. }
  42. }
  43. }
  44. }
  45. ----
  46. ====
  47. [discrete]
  48. [[create-a-data-stream-template]]
  49. === Create an index template
  50. . In {kib}, open the menu and go to *Stack Management > Index Management*.
  51. . In the *Index Templates* tab, click *Create template*.
  52. . In the Create template wizard, use the *Data stream* toggle to indicate the
  53. template is used for data streams.
  54. . Use the wizard to finish defining your template. Specify:
  55. * One or more index patterns that match the data stream's name.
  56. * Mappings and settings for the stream's backing indices.
  57. * A priority for the index template
  58. +
  59. [IMPORTANT]
  60. ====
  61. {es} has built-in index templates for the `metrics-*-*`, `logs-*-*`, and
  62. `synthetics-*-*` index patterns, each with a priority of `100`.
  63. {ingest-guide}/fleet-overview.html[{agent}] uses these templates to
  64. create data streams.
  65. If you use {agent}, assign your index templates a priority lower than `100` to
  66. avoid overriding the built-in templates. Otherwise, use a non-overlapping index
  67. pattern or assign templates with an overlapping pattern a `priority` higher than
  68. `100`.
  69. For example, if you don't use {agent} and want to create a template for the
  70. `logs-*` index pattern, assign your template a priority of `200`. This ensures
  71. your template is applied instead of the built-in template for `logs-*-*`.
  72. ====
  73. If the index template doesn't specify a mapping for the `@timestamp` field, {es}
  74. maps `@timestamp` as a `date` field with default options.
  75. If using {ilm-init}, specify your lifecycle policy in the `index.lifecycle.name`
  76. setting.
  77. TIP: Carefully consider your template's mappings and settings. Later changes may
  78. require reindexing. See <<data-streams-change-mappings-and-settings>>.
  79. [role="screenshot"]
  80. image::images/data-streams/create-index-template.png[Create template page]
  81. [%collapsible]
  82. .API example
  83. ====
  84. Use the <<indices-put-template,put index template API>> to create an index
  85. template. The template must include an empty `data_stream` object, indicating
  86. it's used for data streams.
  87. [source,console]
  88. ----
  89. PUT /_index_template/my-data-stream-template
  90. {
  91. "index_patterns": [ "my-data-stream*" ],
  92. "data_stream": { },
  93. "priority": 200,
  94. "template": {
  95. "settings": {
  96. "index.lifecycle.name": "my-data-stream-policy"
  97. }
  98. }
  99. }
  100. ----
  101. // TEST[continued]
  102. ====
  103. [discrete]
  104. [[create-a-data-stream]]
  105. === Create the data stream
  106. To automatically create the data stream, submit an
  107. <<add-documents-to-a-data-stream,indexing request>> to the stream. The stream's
  108. name must match one of your template's index patterns.
  109. [source,console]
  110. ----
  111. POST /my-data-stream/_doc/
  112. {
  113. "@timestamp": "2020-12-06T11:04:05.000Z",
  114. "user": {
  115. "id": "vlb44hny"
  116. },
  117. "message": "Login attempt failed"
  118. }
  119. ----
  120. // TEST[continued]
  121. You can also use the <<indices-create-data-stream,create data stream API>> to
  122. manually create the data stream. The stream's name must match one of your
  123. template's index patterns.
  124. [source,console]
  125. ----
  126. PUT /_data_stream/my-data-stream
  127. ----
  128. // TEST[continued]
  129. // TEST[s/my-data-stream/my-data-stream-alt/]
  130. [discrete]
  131. [[secure-a-data-stream]]
  132. === Secure the data stream
  133. To control access to the data stream and its
  134. data, use <<data-stream-privileges,{es}'s {security-features}>>.
  135. [discrete]
  136. [[get-info-about-a-data-stream]]
  137. === Get information about a data stream
  138. In {kib}, open the menu and go to *Stack Management > Index Management*. In the
  139. *Data Streams* tab, click the data stream's name.
  140. [role="screenshot"]
  141. image::images/data-streams/data-streams-list.png[Data Streams tab]
  142. [%collapsible]
  143. .API example
  144. ====
  145. Use the <<indices-get-data-stream,get data stream API>> to retrieve information
  146. about one or more data streams:
  147. ////
  148. [source,console]
  149. ----
  150. POST /my-data-stream/_rollover/
  151. ----
  152. // TEST[continued]
  153. ////
  154. [source,console]
  155. ----
  156. GET /_data_stream/my-data-stream
  157. ----
  158. // TEST[continued]
  159. ====
  160. [discrete]
  161. [[delete-a-data-stream]]
  162. === Delete a data stream
  163. To delete a data stream and its backing indices, open the {kib} menu and go to
  164. *Stack Management > Index Management*. In the *Data Streams* tab, click the
  165. trash can icon.
  166. [role="screenshot"]
  167. image::images/data-streams/data-streams-list.png[Data Streams tab]
  168. [%collapsible]
  169. .API example
  170. ====
  171. Use the <<indices-delete-data-stream,delete data stream API>> to delete a data
  172. stream and its backing indices:
  173. [source,console]
  174. ----
  175. DELETE /_data_stream/my-data-stream
  176. ----
  177. // TEST[continued]
  178. ====
  179. ////
  180. [source,console]
  181. ----
  182. DELETE /_data_stream/*
  183. DELETE /_index_template/*
  184. DELETE /_ilm/policy/my-data-stream-policy
  185. ----
  186. // TEST[continued]
  187. ////