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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 index alias to
  10. 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 *Create policy*.
  19. [role="screenshot"]
  20. image::images/ilm/create-policy.png[Create Policy 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_primary_shard_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,create or update index template API>> to create
  105. an index 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": 500,
  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. // tag::time-series-alias-tip[]
  156. Prior to {es} 7.9, you would typically use an <<indices-aliases,index alias>>
  157. with a write index to manage time series data. Data streams replace this
  158. functionality, require less maintenance, and automatically integrate with
  159. <<data-tiers,data tiers>>.
  160. // end::time-series-alias-tip[]
  161. To convert an index alias with a write index to a new data stream with the same
  162. name, use the <<indices-migrate-to-data-stream,migrate to data stream API>>.
  163. During conversion, the alias’s indices become hidden backing indices for the
  164. stream. The alias’s write index becomes the stream’s write index. Note the data
  165. stream still requires a matching <<create-a-data-stream-template,index
  166. template>>.
  167. ////
  168. [source,console]
  169. ----
  170. POST idx1/_doc/
  171. {
  172. "message" : "testing",
  173. "@timestamp" : "2099-01-01"
  174. }
  175. POST idx2/_doc/
  176. {
  177. "message" : "testing2",
  178. "@timestamp" : "2099-01-01"
  179. }
  180. POST /_aliases
  181. {
  182. "actions": [
  183. {
  184. "add": {
  185. "index": "idx1",
  186. "alias": "my-time-series-data",
  187. "is_write_index": true
  188. }
  189. },
  190. {
  191. "add": {
  192. "index": "idx2",
  193. "alias": "my-time-series-data"
  194. }
  195. }
  196. ]
  197. }
  198. PUT /_index_template/template
  199. {
  200. "index_patterns": ["my-time-series-data"],
  201. "data_stream": { }
  202. }
  203. ----
  204. // TEST[continued]
  205. ////
  206. [source,console]
  207. ----
  208. POST /_data_stream/_migrate/my-time-series-data
  209. ----
  210. // TEST[continued]
  211. [discrete]
  212. [[secure-a-data-stream]]
  213. === Secure the data stream
  214. To control access to the data stream and its
  215. data, use <<data-stream-privileges,{es}'s {security-features}>>.
  216. [discrete]
  217. [[get-info-about-a-data-stream]]
  218. === Get information about a data stream
  219. In {kib}, open the menu and go to *Stack Management > Index Management*. In the
  220. *Data Streams* tab, click the data stream's name.
  221. [role="screenshot"]
  222. image::images/data-streams/data-streams-list.png[Data Streams tab]
  223. [%collapsible]
  224. .API example
  225. ====
  226. Use the <<indices-get-data-stream,get data stream API>> to retrieve information
  227. about one or more data streams:
  228. ////
  229. [source,console]
  230. ----
  231. POST /my-data-stream/_rollover/
  232. ----
  233. // TEST[continued]
  234. ////
  235. [source,console]
  236. ----
  237. GET /_data_stream/my-data-stream
  238. ----
  239. // TEST[continued]
  240. ====
  241. [discrete]
  242. [[delete-a-data-stream]]
  243. === Delete a data stream
  244. To delete a data stream and its backing indices, open the {kib} menu and go to
  245. *Stack Management > Index Management*. In the *Data Streams* tab, click the
  246. trash icon. The trash icon only displays if you have the `delete_index`
  247. <<security-privileges, security privilege>> for the data stream.
  248. [role="screenshot"]
  249. image::images/data-streams/data-streams-no-delete.png[Data Streams tab]
  250. [%collapsible]
  251. .API example
  252. ====
  253. Use the <<indices-delete-data-stream,delete data stream API>> to delete a data
  254. stream and its backing indices:
  255. [source,console]
  256. ----
  257. DELETE /_data_stream/my-data-stream
  258. ----
  259. // TEST[continued]
  260. ====
  261. ////
  262. [source,console]
  263. ----
  264. DELETE /_data_stream/*
  265. DELETE /_index_template/*
  266. DELETE /_ilm/policy/my-data-stream-policy
  267. ----
  268. // TEST[continued]
  269. ////