put-lifecycle.asciidoc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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-policy-definition>> 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. [[ilm-put-lifecycle-query-params]]
  31. ==== {api-query-parms-title}
  32. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  33. [[ilm-put-lifecycle-example]]
  34. ==== {api-examples-title}
  35. The following example creates a new policy named `my_policy`. In addition, you can use the
  36. `_meta` parameter to add arbitrary metadata to the policy, the `_meta` parameter is optional
  37. and not automatically generated or used by Elasticsearch. To unset `_meta`, replace the policy
  38. without specifying one. To check the `_meta`, you can use the <<ilm-get-lifecycle,Get lifecycle policy>> API.
  39. [source,console]
  40. --------------------------------------------------
  41. PUT _ilm/policy/my_policy
  42. {
  43. "policy": {
  44. "_meta": {
  45. "description": "used for nginx log",
  46. "project": {
  47. "name": "myProject",
  48. "department": "myDepartment"
  49. }
  50. },
  51. "phases": {
  52. "warm": {
  53. "min_age": "10d",
  54. "actions": {
  55. "forcemerge": {
  56. "max_num_segments": 1
  57. }
  58. }
  59. },
  60. "delete": {
  61. "min_age": "30d",
  62. "actions": {
  63. "delete": {}
  64. }
  65. }
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. If the request succeeds, you receive the following result:
  71. [source,console-result]
  72. ----
  73. {
  74. "acknowledged": true
  75. }
  76. ----