put-lifecycle.asciidoc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. [role="xpack"]
  2. [[ilm-put-lifecycle]]
  3. === Create or update lifecycle policy API
  4. ++++
  5. <titleabbrev>Create or update lifecycle policy</titleabbrev>
  6. ++++
  7. Creates or updates lifecycle policy. See <<ilm-index-lifecycle>> for
  8. definitions of policy components.
  9. [[ilm-put-lifecycle-request]]
  10. ==== {api-request-title}
  11. `PUT _ilm/policy/<policy_id>`
  12. [[ilm-put-lifecycle-prereqs]]
  13. ==== {api-prereq-title}
  14. * If the {es} {security-features} are enabled, you must have the `manage_ilm`
  15. cluster privilege to use this API. You must also have the `manage` index
  16. privilege on all indices being managed by `policy`. {ilm-init} performs
  17. operations as the user who last updated the policy. {ilm-init} only has the
  18. <<defining-roles,roles>> assigned to the user at the time of the last policy
  19. update.
  20. [[ilm-put-lifecycle-desc]]
  21. ==== {api-description-title}
  22. Creates a lifecycle policy. If the specified policy exists, the policy is
  23. replaced and the policy version is incremented.
  24. NOTE: Only the latest version of the policy is stored, you cannot revert to
  25. previous versions.
  26. [[ilm-put-lifecycle-path-params]]
  27. ==== {api-path-parms-title}
  28. `<policy_id>`::
  29. (Required, string) Identifier for the policy.
  30. +
  31. [IMPORTANT]
  32. ====
  33. To avoid naming collisions with built-in and Fleet-managed ILM policies, avoid using `@` as part of the id of your own ILM policies.
  34. ====
  35. [[ilm-put-lifecycle-query-params]]
  36. ==== {api-query-parms-title}
  37. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  38. [[ilm-put-lifecycle-example]]
  39. ==== {api-examples-title}
  40. The following example creates a new policy named `my_policy`. In addition, you can use the
  41. `_meta` parameter to add arbitrary metadata to the policy, the `_meta` parameter is optional
  42. and not automatically generated or used by Elasticsearch. To unset `_meta`, replace the policy
  43. without specifying one. To check the `_meta`, you can use the <<ilm-get-lifecycle,Get lifecycle policy>> API.
  44. [source,console]
  45. --------------------------------------------------
  46. PUT _ilm/policy/my_policy
  47. {
  48. "policy": {
  49. "_meta": {
  50. "description": "used for nginx log",
  51. "project": {
  52. "name": "myProject",
  53. "department": "myDepartment"
  54. }
  55. },
  56. "phases": {
  57. "warm": {
  58. "min_age": "10d",
  59. "actions": {
  60. "forcemerge": {
  61. "max_num_segments": 1
  62. }
  63. }
  64. },
  65. "delete": {
  66. "min_age": "30d",
  67. "actions": {
  68. "delete": {}
  69. }
  70. }
  71. }
  72. }
  73. }
  74. --------------------------------------------------
  75. If the request succeeds, you receive the following result:
  76. [source,console-result]
  77. ----
  78. {
  79. "acknowledged": true
  80. }
  81. ----