put-lifecycle.asciidoc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[ilm-put-lifecycle]]
  4. === Create lifecycle policy API
  5. ++++
  6. <titleabbrev>Create policy</titleabbrev>
  7. ++++
  8. Creates or updates lifecycle policy. See <<ilm-policy-definition,Policy phases and actions>>
  9. for definitions of policy components.
  10. ==== Request
  11. `PUT _ilm/policy/<policy_id>`
  12. ==== Description
  13. Creates a lifecycle policy. If the specified policy exists, the policy is
  14. replaced and the policy version is incremented.
  15. NOTE: Only the latest version of the policy is stored, you cannot revert to
  16. previous versions.
  17. ==== Path Parameters
  18. `policy` (required)::
  19. (string) Identifier for the policy.
  20. ==== Request Parameters
  21. include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  22. ==== Authorization
  23. You must have the `manage_ilm` cluster privilege to use this API. You must
  24. also have the `manage` index privilege on all indices being managed by `policy`.
  25. All operations executed by {ilm} for a policy are executed as the user that
  26. put the latest version of a policy.
  27. For more information, see {stack-ov}/security-privileges.html[Security Privileges].
  28. ==== Examples
  29. The following example creates a new policy named `my_policy`:
  30. [source,js]
  31. --------------------------------------------------
  32. PUT _ilm/policy/my_policy
  33. {
  34. "policy": {
  35. "phases": {
  36. "warm": {
  37. "min_age": "10d",
  38. "actions": {
  39. "forcemerge": {
  40. "max_num_segments": 1
  41. }
  42. }
  43. },
  44. "delete": {
  45. "min_age": "30d",
  46. "actions": {
  47. "delete": {}
  48. }
  49. }
  50. }
  51. }
  52. }
  53. --------------------------------------------------
  54. // CONSOLE
  55. // TEST
  56. If the request succeeds, you receive the following result:
  57. [source,console-result]
  58. ----
  59. {
  60. "acknowledged": true
  61. }
  62. ----