getting-started-ilm.asciidoc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[getting-started-index-lifecycle-management]]
  4. == Getting started with {ilm}
  5. beta[]
  6. Let's jump into {ilm} ({ilm-init}) by working through a hands-on scenario.
  7. This section will leverage many new concepts unique to {ilm-init} that
  8. you may not be familiar with. The following sections will explore
  9. these in more details.
  10. The goal of this example is to set up a set of indices that will encapsulate
  11. the data from a time series data source. We can imagine there is a system
  12. like {filebeat-ref}[Filebeat] that continuously indexes documents into
  13. our writing index. We wish to roll over the index after it reaches a size
  14. of 50 gigabytes, or has been created 30 days ago, and then delete the index
  15. after 90 days.
  16. === Setting up a new policy
  17. beta[]
  18. There are many new features introduced by {ilm-init}, but we will only focus on
  19. a few that are needed for our example. For starters, we will use the
  20. <<ilm-put-lifecycle,Put Policy>> API to define our first policy. Lifecycle
  21. policies are defined in JSON and include specific
  22. <<ilm-policy-definition,phases and actions>>.
  23. [source,js]
  24. ------------------------
  25. PUT _ilm/policy/datastream_policy <1>
  26. {
  27. "policy": { <2>
  28. "phases": {
  29. "hot": { <3>
  30. "actions": {
  31. "rollover": { <4>
  32. "max_size": "50GB",
  33. "max_age": "30d"
  34. }
  35. }
  36. },
  37. "delete": {
  38. "min_age": "90d", <5>
  39. "actions": {
  40. "delete": {} <6>
  41. }
  42. }
  43. }
  44. }
  45. }
  46. ------------------------
  47. // CONSOLE
  48. // TEST
  49. <1> call to the <<ilm-put-lifecycle,put lifecycle API>> endpoint to create
  50. a new policy named "datastream_policy"
  51. <2> policy definition sub-object
  52. <3> the hot phase defined in the "phases" section. Optional `min_age` field
  53. not defined -- defaults to `0ms`
  54. <4> rollover action definition
  55. <5> delete phase begins after 90 days
  56. <6> delete action definition
  57. Here we created the policy called `datastream_policy` which rolls over
  58. the index being written to after it reaches 50 gigabytes, or it is 30
  59. days old. The rollover will occur when either of these conditions is true.
  60. The index will be deleted 90 days after it is rolled over.
  61. === Applying a policy to our index
  62. beta[]
  63. There are <<set-up-lifecycle-policy,a few ways>> to associate a
  64. policy to an index. Since we wish specific settings to be applied to
  65. the new index created from Rollover, we will set the policy via
  66. index templates.
  67. [source,js]
  68. -----------------------
  69. PUT _template/datastream_template
  70. {
  71. "index_patterns": ["datastream-*"], <1>
  72. "settings": {
  73. "number_of_shards": 1,
  74. "number_of_replicas": 1,
  75. "index.lifecycle.name": "datastream_policy", <2>
  76. "index.lifecycle.rollover_alias": "datastream" <3>
  77. }
  78. }
  79. -----------------------
  80. // CONSOLE
  81. // TEST[continued]
  82. <1> match all indices starting with "datastream-". These will include all
  83. newly created indices from actions like rollover
  84. <2> the name of the lifecycle policy managing the index
  85. <3> alias to use for the rollover action, required since a rollover action is
  86. defined in the policy.
  87. The above index template introduces a few new settings specific to {ilm-init}.
  88. The first being `index.lifecycle.name`. This setting will configure
  89. the "datastream_policy" to the index applying this template. This means
  90. that all newly created indices prefixed "datastream-" will be managed by
  91. our policy. The other setting used here is `index.lifecycle.rollover_alias`.
  92. This setting is required when using a policy containing the rollover
  93. action and specifies which alias to rollover on behalf of this index.
  94. The intention here is that the rollover alias is also defined on the index.
  95. To begin, we will want to bootstrap our first index to write to.
  96. [source,js]
  97. -----------------------
  98. PUT datastream-000001
  99. {
  100. "aliases": {
  101. "datastream": {
  102. "is_write_index": true
  103. }
  104. }
  105. }
  106. -----------------------
  107. // CONSOLE
  108. // TEST[continued]
  109. When creating our index, we have to consider a few important configurations
  110. that tie our index and our policy together correctly. We need to make sure
  111. that our index name matches our index template pattern of "datastream-*",
  112. which it does. We are using the <<ilm-rollover-action, Rollover Action>> in our policy, which
  113. requires that our index name ends with a number. In our case, we used
  114. `000001`. This is important so that Rollover can increment this number when
  115. naming the new index created from rolling over.
  116. Our index creation request leverages its template to apply our settings,
  117. but we must also configure our rollover alias: "datastream". To do this,
  118. we take advantage of <<aliases-write-index,write indices>>. This is a way
  119. to define an alias to be used for both reading and writing, with only one
  120. index being the index that is being written to at a time. Rollover swaps
  121. the write index to be the new index created from rollover, and sets the
  122. alias to be read-only for the source index.
  123. === Checking progress
  124. beta[]
  125. Now that we have an index managed by our policy, how do we tell what is going
  126. on? Which phase are we in? Is something broken? This section will go over a
  127. few APIs and their responses to help us inspect our indices with respect
  128. to {ilm-init}.
  129. With the help of the <<ilm-explain-lifecycle,Explain API>>, we can know
  130. things like which phase we're in and when we entered that phase. The API
  131. will also provide further info if errors occurred, or if we are blocked on
  132. certain checks within actions.
  133. [source,js]
  134. --------------------------------------------------
  135. GET datastream-*/_ilm/explain
  136. --------------------------------------------------
  137. // CONSOLE
  138. // TEST[continued]
  139. The above request will retrieve {ilm-init} execution information for all our
  140. managed indices.
  141. [source,js]
  142. --------------------------------------------------
  143. {
  144. "indices": {
  145. "datastream-000001": {
  146. "index": "datastream-000001",
  147. "managed": true, <1>
  148. "policy": "datastream_policy", <2>
  149. "lifecycle_date_millis": 1538475653281,
  150. "phase": "hot", <3>
  151. "phase_time_millis": 1538475653317,
  152. "action": "rollover", <4>
  153. "action_time_millis": 1538475653317,
  154. "step": "attempt-rollover", <5>
  155. "step_time_millis": 1538475653317,
  156. "phase_execution": {
  157. "policy": "datastream_policy",
  158. "phase_definition": { <6>
  159. "min_age": "0ms",
  160. "actions": {
  161. "rollover": {
  162. "max_size": "50gb",
  163. "max_age": "30d"
  164. }
  165. }
  166. },
  167. "version": 1, <7>
  168. "modified_date_in_millis": 1539609701576
  169. }
  170. }
  171. }
  172. }
  173. --------------------------------------------------
  174. // CONSOLE
  175. // TESTRESPONSE[skip:no way to know if we will get this response immediately]
  176. <1> this index is managed by ILM
  177. <2> the policy in question, in this case, "datastream_policy"
  178. <3> what phase the index is currently in
  179. <4> what action the index is currently on
  180. <5> what step the index is currently on
  181. <6> the definition of the phase
  182. (in this case, the "hot" phase) that the index is currently on
  183. <7> the version of the policy being used to execute the current phase
  184. You can read about the full details of this response in the
  185. <<ilm-explain-lifecycle, explain API docs>>. For now, let's focus on how
  186. the response details which phase, action, and step we're in. We are in the
  187. "hot" phase, and "rollover" action. Rollover will continue to be called
  188. by {ilm-init} until its conditions are met and it rolls over the index.
  189. Afterwards, the original index will stay in the hot phase until 90 more
  190. days pass and it is deleted in the delete phase.
  191. As time goes on, new indices will be created and deleted.
  192. With `datastream-000002` being created when the index mets the rollover
  193. conditions and `datastream-000003` created after that. We will be able
  194. to search across all of our managed indices using the "datastream" alias,
  195. and we will be able to write to our to-be-rolled-over write indices using
  196. that same alias.
  197. That's it! We have our first use-case managed by {ilm-init}.
  198. To learn more about all our APIs,
  199. check out <<index-lifecycle-management-api,ILM APIs>>.