tutorial-migrate-data-stream-from-ilm-to-dsl.asciidoc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. [role="xpack"]
  2. [[tutorial-migrate-data-stream-from-ilm-to-dsl]]
  3. === Tutorial: Migrate ILM managed data stream to Data stream lifecycle
  4. preview:[]
  5. In this tutorial we'll look at migrating an existing data stream from {ilm-init} to
  6. Data stream lifecycle. The existing {ilm-init} managed backing indices will continue
  7. to be managed by {ilm-init} until they age out and get deleted by {ilm-init}; however,
  8. the new backing indices will be managed by Data stream lifecycle.
  9. This way, a data stream is gradually migrated away from being managed by {ilm-cap} to
  10. being managed by Data stream lifecycle. As we'll see, {ilm-cap} and Data stream lifecycle
  11. can co-manage a data stream; however, an index can only be managed by one system at
  12. a time.
  13. Let's first create a data stream with two backing indices managed by {ilm-cap}.
  14. We first create an {ilm-cap} policy:
  15. [source,console]
  16. ----
  17. PUT _ilm/policy/pre-dsl-ilm-policy
  18. {
  19. "policy": {
  20. "phases": {
  21. "hot": {
  22. "actions": {
  23. "rollover": {
  24. "max_primary_shard_size": "50gb"
  25. }
  26. }
  27. },
  28. "delete": {
  29. "min_age": "7d",
  30. "actions": {
  31. "delete": {}
  32. }
  33. }
  34. }
  35. }
  36. }
  37. ----
  38. And let's create an index template that'll back the data stream and configures {ilm-cap}:
  39. [source,console]
  40. ----
  41. PUT _index_template/dsl-data-stream-template
  42. {
  43. "index_patterns": ["dsl-data-stream*"],
  44. "data_stream": { },
  45. "priority": 500,
  46. "template": {
  47. "settings": {
  48. "index.lifecycle.name": "pre-dsl-ilm-policy"
  49. }
  50. }
  51. }
  52. ----
  53. // TEST[continued]
  54. We'll now index a document targetting `dsl-data-stream` to create the data stream
  55. and we'll also manually rollover the data stream to have another generation index created:
  56. [source,console]
  57. ----
  58. POST dsl-data-stream/_doc?
  59. {
  60. "@timestamp": "2023-10-18T16:21:15.000Z",
  61. "message": "192.0.2.42 - - [06/May/2099:16:21:15 +0000] \"GET /images/bg.jpg HTTP/1.0\" 200 24736"
  62. }
  63. ----
  64. // TEST[continued]
  65. [source,console]
  66. ----
  67. POST dsl-data-stream/_rollover
  68. ----
  69. // TEST[continued]
  70. We'll use the <<indices-get-data-stream, GET _data_stream>> API to inspect the state of
  71. the data stream:
  72. [source,console]
  73. --------------------------------------------------
  74. GET _data_stream/dsl-data-stream
  75. --------------------------------------------------
  76. // TEST[continued]
  77. Inspecting the response we'll see that both backing indices are managed by {ilm-init}
  78. and that the next generation index will also be managed by {ilm-init}:
  79. [source,console-result]
  80. ----
  81. {
  82. "data_streams": [
  83. {
  84. "name": "dsl-data-stream",
  85. "timestamp_field": {
  86. "name": "@timestamp"
  87. },
  88. "indices": [
  89. {
  90. "index_name": ".ds-dsl-data-stream-2023.10.19-000001", <1>
  91. "index_uuid": "xCEhwsp8Tey0-FLNFYVwSg",
  92. "prefer_ilm": true, <2>
  93. "ilm_policy": "pre-dsl-ilm-policy", <3>
  94. "managed_by": "Index Lifecycle Management" <4>
  95. },
  96. {
  97. "index_name": ".ds-dsl-data-stream-2023.10.19-000002",
  98. "index_uuid": "PA_JquKGSiKcAKBA8DJ5gw",
  99. "prefer_ilm": true,
  100. "ilm_policy": "pre-dsl-ilm-policy",
  101. "managed_by": "Index Lifecycle Management"
  102. }
  103. ],
  104. "generation": 2,
  105. "status": "GREEN",
  106. "template": "dsl-data-stream-template",
  107. "next_generation_managed_by": "Index Lifecycle Management", <5>
  108. "prefer_ilm": true, <6>
  109. "ilm_policy": "pre-dsl-ilm-policy", <7>
  110. "hidden": false,
  111. "system": false,
  112. "allow_custom_routing": false,
  113. "replicated": false
  114. }
  115. ]
  116. }
  117. ----
  118. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000001"/"index_name": $body.data_streams.0.indices.0.index_name/]
  119. // TESTRESPONSE[s/"index_uuid": "xCEhwsp8Tey0-FLNFYVwSg"/"index_uuid": $body.data_streams.0.indices.0.index_uuid/]
  120. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000002"/"index_name": $body.data_streams.0.indices.1.index_name/]
  121. // TESTRESPONSE[s/"index_uuid": "PA_JquKGSiKcAKBA8DJ5gw"/"index_uuid": $body.data_streams.0.indices.1.index_uuid/]
  122. // TESTRESPONSE[s/"status": "GREEN"/"status": "YELLOW"/]
  123. <1> The name of the backing index.
  124. <2> For each backing index we display the value of the <<index-lifecycle-prefer-ilm, prefer_ilm>>
  125. configuration which will indicate if {ilm-init} takes precedence over data stream lifecycle in case
  126. both systems are configured for an index.
  127. <3> The {ilm-ini} policy configured for this index.
  128. <4> The system that manages this index (possible values are "Index Lifecycle Management",
  129. "Data stream lifecycle", or "Unmanaged")
  130. <5> The system that will manage the next generation index (the new write index of this
  131. data stream, once the data stream is rolled over). The possible values are
  132. "Index Lifecycle Management", "Data stream lifecycle", or "Unmanaged".
  133. <6> The <<index-lifecycle-prefer-ilm, prefer_ilm>> value configured in the index template
  134. that's backing the data stream. This value will be configured for all the new backing indices.
  135. If it's not configured in the index template the backing indices will receive the `true`
  136. default value ({ilm-init} takes precedence over data stream lifecycle by default as it's
  137. currently richer in features).
  138. <7> The {ilm-init} policy configured in the index template that's backing this data
  139. stream (which will be configured on all the new backing indices, as long as it exists
  140. in the index template).
  141. To migrate the `dsl-data-stream` to data stream lifecycle we'll have to execute
  142. two steps:
  143. 1. Update the index template that's backing the index template to configure <<index-lifecycle-prefer-ilm, prefer_ilm>>
  144. to `false`, and to configure data stream lifecycle.
  145. 2. Configure the data stream lifecycle for the _existing_ `dsl-data-stream` using
  146. the <<data-streams-put-lifecycle, lifecycle API>>.
  147. IMPORTANT: The data stream lifecycle configuration that's added to the index template,
  148. being a data stream configuration, will only apply to **new** data streams.
  149. Our data stream exists already, so even though we added a data stream lifecycle
  150. configuration in the index template it will not be applied to `dsl-data-stream`.
  151. [[update-index-template-for-dsl]]
  152. Let's update the index template:
  153. [source,console]
  154. ----
  155. PUT _index_template/dsl-data-stream-template
  156. {
  157. "index_patterns": ["dsl-data-stream*"],
  158. "data_stream": { },
  159. "priority": 500,
  160. "template": {
  161. "settings": {
  162. "index.lifecycle.name": "pre-dsl-ilm-policy",
  163. "index.lifecycle.prefer_ilm": false <1>
  164. },
  165. "lifecycle": {
  166. "data_retention": "7d" <2>
  167. }
  168. }
  169. }
  170. ----
  171. // TEST[continued]
  172. <1> The `prefer_ilm` setting will now be configured on the **new** backing indices
  173. (created by rolling over the data stream) such that {ilm-init} does _not_ take
  174. precedence over Data stream lifecycle.
  175. <2> We're configuring the data stream lifecycle so _new_ data streams will be
  176. managed by Data stream lifecycle.
  177. We've now make sure that new data streams will be managed by Data stream lifecycle.
  178. Let's update our existing `dsl-data-stream` and configure Data stream lifecycle:
  179. [source,console]
  180. ----
  181. PUT _data_stream/dsl-data-stream/_lifecycle
  182. {
  183. "data_retention": "7d"
  184. }
  185. ----
  186. // TEST[continued]
  187. We can inspect the data stream to check that the next generation will indeed be
  188. managed by Data stream lifecycle:
  189. [source,console]
  190. --------------------------------------------------
  191. GET _data_stream/dsl-data-stream
  192. --------------------------------------------------
  193. // TEST[continued]
  194. [source,console-result]
  195. ----
  196. {
  197. "data_streams": [
  198. {
  199. "name": "dsl-data-stream",
  200. "timestamp_field": {
  201. "name": "@timestamp"
  202. },
  203. "indices": [
  204. {
  205. "index_name": ".ds-dsl-data-stream-2023.10.19-000001",
  206. "index_uuid": "xCEhwsp8Tey0-FLNFYVwSg",
  207. "prefer_ilm": true,
  208. "ilm_policy": "pre-dsl-ilm-policy",
  209. "managed_by": "Index Lifecycle Management" <1>
  210. },
  211. {
  212. "index_name": ".ds-dsl-data-stream-2023.10.19-000002",
  213. "index_uuid": "PA_JquKGSiKcAKBA8DJ5gw",
  214. "prefer_ilm": true,
  215. "ilm_policy": "pre-dsl-ilm-policy",
  216. "managed_by": "Index Lifecycle Management" <2>
  217. }
  218. ],
  219. "generation": 2,
  220. "status": "GREEN",
  221. "template": "dsl-data-stream-template",
  222. "lifecycle": {
  223. "enabled": true,
  224. "data_retention": "7d"
  225. },
  226. "ilm_policy": "pre-dsl-ilm-policy",
  227. "next_generation_managed_by": "Data stream lifecycle", <3>
  228. "prefer_ilm": false, <4>
  229. "hidden": false,
  230. "system": false,
  231. "allow_custom_routing": false,
  232. "replicated": false
  233. }
  234. ]
  235. }
  236. ----
  237. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000001"/"index_name": $body.data_streams.0.indices.0.index_name/]
  238. // TESTRESPONSE[s/"index_uuid": "xCEhwsp8Tey0-FLNFYVwSg"/"index_uuid": $body.data_streams.0.indices.0.index_uuid/]
  239. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000002"/"index_name": $body.data_streams.0.indices.1.index_name/]
  240. // TESTRESPONSE[s/"index_uuid": "PA_JquKGSiKcAKBA8DJ5gw"/"index_uuid": $body.data_streams.0.indices.1.index_uuid/]
  241. // TESTRESPONSE[s/"status": "GREEN"/"status": "YELLOW"/]
  242. <1> The existing backing index will continue to be managed by {ilm-init}
  243. <2> The existing backing index will continue to be managed by {ilm-init}
  244. <3> The next generation index will be managed by Data stream lifecycle
  245. <4> The `prefer_ilm` setting value we configured in the index template is reflected
  246. and will be configured accordingly for new backing indices.
  247. We'll now rollover the data stream to see the new generation index being managed by
  248. Data stream lifecycle:
  249. [source,console]
  250. ----
  251. POST dsl-data-stream/_rollover
  252. ----
  253. // TEST[continued]
  254. [source,console]
  255. ----
  256. GET _data_stream/dsl-data-stream
  257. ----
  258. // TEST[continued]
  259. [source,console-result]
  260. ----
  261. {
  262. "data_streams": [
  263. {
  264. "name": "dsl-data-stream",
  265. "timestamp_field": {
  266. "name": "@timestamp"
  267. },
  268. "indices": [
  269. {
  270. "index_name": ".ds-dsl-data-stream-2023.10.19-000001",
  271. "index_uuid": "xCEhwsp8Tey0-FLNFYVwSg",
  272. "prefer_ilm": true,
  273. "ilm_policy": "pre-dsl-ilm-policy",
  274. "managed_by": "Index Lifecycle Management" <1>
  275. },
  276. {
  277. "index_name": ".ds-dsl-data-stream-2023.10.19-000002",
  278. "index_uuid": "PA_JquKGSiKcAKBA8DJ5gw",
  279. "prefer_ilm": true,
  280. "ilm_policy": "pre-dsl-ilm-policy",
  281. "managed_by": "Index Lifecycle Management" <2>
  282. },
  283. {
  284. "index_name": ".ds-dsl-data-stream-2023.10.19-000003",
  285. "index_uuid": "PA_JquKGSiKcAKBA8abcd1",
  286. "prefer_ilm": false, <3>
  287. "ilm_policy": "pre-dsl-ilm-policy",
  288. "managed_by": "Data stream lifecycle" <4>
  289. }
  290. ],
  291. "generation": 3,
  292. "status": "GREEN",
  293. "template": "dsl-data-stream-template",
  294. "lifecycle": {
  295. "enabled": true,
  296. "data_retention": "7d"
  297. },
  298. "ilm_policy": "pre-dsl-ilm-policy",
  299. "next_generation_managed_by": "Data stream lifecycle",
  300. "prefer_ilm": false,
  301. "hidden": false,
  302. "system": false,
  303. "allow_custom_routing": false,
  304. "replicated": false
  305. }
  306. ]
  307. }
  308. ----
  309. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000001"/"index_name": $body.data_streams.0.indices.0.index_name/]
  310. // TESTRESPONSE[s/"index_uuid": "xCEhwsp8Tey0-FLNFYVwSg"/"index_uuid": $body.data_streams.0.indices.0.index_uuid/]
  311. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000002"/"index_name": $body.data_streams.0.indices.1.index_name/]
  312. // TESTRESPONSE[s/"index_uuid": "PA_JquKGSiKcAKBA8DJ5gw"/"index_uuid": $body.data_streams.0.indices.1.index_uuid/]
  313. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000003"/"index_name": $body.data_streams.0.indices.2.index_name/]
  314. // TESTRESPONSE[s/"index_uuid": "PA_JquKGSiKcAKBA8abcd1"/"index_uuid": $body.data_streams.0.indices.2.index_uuid/]
  315. // TESTRESPONSE[s/"status": "GREEN"/"status": "YELLOW"/]
  316. <1> The backing indices that existed before rollover will continue to be managed by {ilm-init}
  317. <2> The backing indices that existed before rollover will continue to be managed by {ilm-init}
  318. <3> The new write index received the `false` value for the `prefer_ilm` setting, as we configured
  319. in the index template
  320. <4> The new write index is managed by `Data stream lifecycle`
  321. We can easily change this data stream to be managed by {ilm-cap} because we didn't remove
  322. the {ilm-cap} policy when we <<update-index-template-for-dsl, updated
  323. the index template>>.
  324. We can achieve this in two ways:
  325. 1. <<data-streams-delete-lifecycle, Delete the lifecycle>> from the data streams
  326. 2. Disable Data stream lifecycle by configured the `enabled` flag to `false`.
  327. Let's implement option 2 and disable the data stream lifecycle:
  328. [source,console]
  329. ----
  330. PUT _data_stream/dsl-data-stream/_lifecycle
  331. {
  332. "data_retention": "7d",
  333. "enabled": false <1>
  334. }
  335. ----
  336. // TEST[continued]
  337. <1> The `enabled` flag can be ommitted and defaults to `true` however, here we
  338. explicitly configure it to `false`
  339. Let's check the state of the data stream:
  340. [source,console]
  341. ----
  342. GET _data_stream/dsl-data-stream
  343. ----
  344. // TEST[continued]
  345. [source,console-result]
  346. ----
  347. {
  348. "data_streams": [
  349. {
  350. "name": "dsl-data-stream",
  351. "timestamp_field": {
  352. "name": "@timestamp"
  353. },
  354. "indices": [
  355. {
  356. "index_name": ".ds-dsl-data-stream-2023.10.19-000001",
  357. "index_uuid": "xCEhwsp8Tey0-FLNFYVwSg",
  358. "prefer_ilm": true,
  359. "ilm_policy": "pre-dsl-ilm-policy",
  360. "managed_by": "Index Lifecycle Management"
  361. },
  362. {
  363. "index_name": ".ds-dsl-data-stream-2023.10.19-000002",
  364. "index_uuid": "PA_JquKGSiKcAKBA8DJ5gw",
  365. "prefer_ilm": true,
  366. "ilm_policy": "pre-dsl-ilm-policy",
  367. "managed_by": "Index Lifecycle Management"
  368. },
  369. {
  370. "index_name": ".ds-dsl-data-stream-2023.10.19-000003",
  371. "index_uuid": "PA_JquKGSiKcAKBA8abcd1",
  372. "prefer_ilm": false,
  373. "ilm_policy": "pre-dsl-ilm-policy",
  374. "managed_by": "Index Lifecycle Management" <1>
  375. }
  376. ],
  377. "generation": 3,
  378. "status": "GREEN",
  379. "template": "dsl-data-stream-template",
  380. "lifecycle": {
  381. "enabled": false, <2>
  382. "data_retention": "7d"
  383. },
  384. "ilm_policy": "pre-dsl-ilm-policy",
  385. "next_generation_managed_by": "Index Lifecycle Management", <3>
  386. "prefer_ilm": false,
  387. "hidden": false,
  388. "system": false,
  389. "allow_custom_routing": false,
  390. "replicated": false
  391. }
  392. ]
  393. }
  394. ----
  395. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000001"/"index_name": $body.data_streams.0.indices.0.index_name/]
  396. // TESTRESPONSE[s/"index_uuid": "xCEhwsp8Tey0-FLNFYVwSg"/"index_uuid": $body.data_streams.0.indices.0.index_uuid/]
  397. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000002"/"index_name": $body.data_streams.0.indices.1.index_name/]
  398. // TESTRESPONSE[s/"index_uuid": "PA_JquKGSiKcAKBA8DJ5gw"/"index_uuid": $body.data_streams.0.indices.1.index_uuid/]
  399. // TESTRESPONSE[s/"index_name": ".ds-dsl-data-stream-2023.10.19-000003"/"index_name": $body.data_streams.0.indices.2.index_name/]
  400. // TESTRESPONSE[s/"index_uuid": "PA_JquKGSiKcAKBA8abcd1"/"index_uuid": $body.data_streams.0.indices.2.index_uuid/]
  401. // TESTRESPONSE[s/"status": "GREEN"/"status": "YELLOW"/]
  402. <1> The write index is now managed by {ilm-cap}
  403. <2> The `lifecycle` configured on the data stream is now disabled.
  404. <3> The next write index will be managed by {ilm-cap}
  405. Had we removed the {ilm-cap} policy from the index template when we <<update-index-template-for-dsl, updated>>
  406. it, the write index of the data stream will now be `Unmanaged` because the index
  407. wouldn't have the {ilm-cap} policy configured to fallback onto.
  408. //////////////////////////
  409. [source,console]
  410. --------------------------------------------------
  411. DELETE _data_stream/dsl-data-stream
  412. DELETE _index_template/dsl-data-stream-template
  413. DELETE _ilm/policy/pre-dsl-ilm-policy
  414. --------------------------------------------------
  415. // TEST[continued]
  416. //////////////////////////