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

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