1
0

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

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