put-lifecycle.asciidoc 2.5 KB

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