flush.asciidoc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. [[indices-flush]]
  2. === Flush
  3. The flush API allows to flush one or more indices through an API. The
  4. flush process of an index makes sure that any data that is currently only
  5. persisted in the <<index-modules-translog,transaction log>> is also permanently
  6. persisted in Lucene. This reduces recovery times as that data doesn't need to be
  7. reindexed from the transaction logs after the Lucene indexed is opened. By
  8. default, Elasticsearch uses heuristics in order to automatically
  9. trigger flushes as required. It is rare for users to need to call the API directly.
  10. [source,js]
  11. --------------------------------------------------
  12. POST twitter/_flush
  13. --------------------------------------------------
  14. // CONSOLE
  15. // TEST[setup:twitter]
  16. [float]
  17. [[flush-parameters]]
  18. ==== Request Parameters
  19. The flush API accepts the following request parameters:
  20. [horizontal]
  21. `wait_if_ongoing`:: If set to `true`(the default value) the flush operation will
  22. block until the flush can be executed if another flush operation is already executing.
  23. `force`:: Whether a flush should be forced even if it is not necessarily needed i.e.
  24. if no changes will be committed to the index. This is useful if transaction log IDs
  25. should be incremented even if no uncommitted changes are present.
  26. (This setting can be considered as internal)
  27. [float]
  28. [[flush-multi-index]]
  29. ==== Multi Index
  30. The flush API can be applied to more than one index with a single call,
  31. or even on `_all` the indices.
  32. [source,js]
  33. --------------------------------------------------
  34. POST kimchy,elasticsearch/_flush
  35. POST _flush
  36. --------------------------------------------------
  37. // CONSOLE
  38. // TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]
  39. [[synced-flush-api]]
  40. ==== Synced Flush
  41. Elasticsearch tracks the indexing activity of each shard. Shards that have not
  42. received any indexing operations for 5 minutes are automatically marked as inactive. This presents
  43. an opportunity for Elasticsearch to reduce shard resources and also perform
  44. a special kind of flush, called `synced flush`. A synced flush performs a normal flush, then adds
  45. a generated unique marker (sync_id) to all shards.
  46. Since the sync id marker was added when there were no ongoing indexing operations, it can
  47. be used as a quick way to check if the two shards' lucene indices are identical. This quick sync id
  48. comparison (if present) is used during recovery or restarts to skip the first and
  49. most costly phase of the process. In that case, no segment files need to be copied and
  50. the transaction log replay phase of the recovery can start immediately. Note that since the sync id
  51. marker was applied together with a flush, it is very likely that the transaction log will be empty,
  52. speeding up recoveries even more.
  53. This is particularly useful for use cases having lots of indices which are
  54. never or very rarely updated, such as time based data. This use case typically generates lots of indices whose
  55. recovery without the synced flush marker would take a long time.
  56. To check whether a shard has a marker or not, look for the `commit` section of shard stats returned by
  57. the <<indices-stats,indices stats>> API:
  58. [source,sh]
  59. --------------------------------------------------
  60. GET twitter/_stats?filter_path=**.commit&level=shards <1>
  61. --------------------------------------------------
  62. // CONSOLE
  63. // TEST[s/^/PUT twitter\nPOST twitter\/_flush\/synced\n/]
  64. <1> `filter_path` is used to reduce the verbosity of the response, but is entirely optional
  65. which returns something similar to:
  66. [source,js]
  67. --------------------------------------------------
  68. {
  69. "indices": {
  70. "twitter": {
  71. "shards": {
  72. "0": [
  73. {
  74. "commit" : {
  75. "id" : "3M3zkw2GHMo2Y4h4/KFKCg==",
  76. "generation" : 3,
  77. "user_data" : {
  78. "translog_uuid" : "hnOG3xFcTDeoI_kvvvOdNA",
  79. "history_uuid" : "XP7KDJGiS1a2fHYiFL5TXQ",
  80. "local_checkpoint" : "-1",
  81. "translog_generation" : "2",
  82. "max_seq_no" : "-1",
  83. "sync_id" : "AVvFY-071siAOuFGEO9P", <1>
  84. "max_unsafe_auto_id_timestamp" : "-1",
  85. "min_retained_seq_no" : "0"
  86. },
  87. "num_docs" : 0
  88. }
  89. }
  90. ]
  91. }
  92. }
  93. }
  94. }
  95. --------------------------------------------------
  96. // TESTRESPONSE[s/"id" : "3M3zkw2GHMo2Y4h4\/KFKCg=="/"id": $body.indices.twitter.shards.0.0.commit.id/]
  97. // TESTRESPONSE[s/"translog_uuid" : "hnOG3xFcTDeoI_kvvvOdNA"/"translog_uuid": $body.indices.twitter.shards.0.0.commit.user_data.translog_uuid/]
  98. // TESTRESPONSE[s/"history_uuid" : "XP7KDJGiS1a2fHYiFL5TXQ"/"history_uuid": $body.indices.twitter.shards.0.0.commit.user_data.history_uuid/]
  99. // TESTRESPONSE[s/"sync_id" : "AVvFY-071siAOuFGEO9P"/"sync_id": $body.indices.twitter.shards.0.0.commit.user_data.sync_id/]
  100. <1> the `sync id` marker
  101. [float]
  102. ==== Synced Flush API
  103. The Synced Flush API allows an administrator to initiate a synced flush manually. This can be particularly useful for
  104. a planned (rolling) cluster restart where you can stop indexing and don't want to wait the default 5 minutes for
  105. idle indices to be sync-flushed automatically.
  106. While handy, there are a couple of caveats for this API:
  107. 1. Synced flush is a best effort operation. Any ongoing indexing operations will cause
  108. the synced flush to fail on that shard. This means that some shards may be synced flushed while others aren't. See below for more.
  109. 2. The `sync_id` marker is removed as soon as the shard is flushed again. That is because a flush replaces the low level
  110. lucene commit point where the marker is stored. Uncommitted operations in the transaction log do not remove the marker.
  111. In practice, one should consider any indexing operation on an index as removing the marker as a flush can be triggered by Elasticsearch
  112. at any time.
  113. NOTE: It is harmless to request a synced flush while there is ongoing indexing. Shards that are idle will succeed and shards
  114. that are not will fail. Any shards that succeeded will have faster recovery times.
  115. [source,sh]
  116. --------------------------------------------------
  117. POST twitter/_flush/synced
  118. --------------------------------------------------
  119. // CONSOLE
  120. // TEST[setup:twitter]
  121. The response contains details about how many shards were successfully sync-flushed and information about any failure.
  122. Here is what it looks like when all shards of a two shards and one replica index successfully
  123. sync-flushed:
  124. [source,js]
  125. --------------------------------------------------
  126. {
  127. "_shards": {
  128. "total": 2,
  129. "successful": 2,
  130. "failed": 0
  131. },
  132. "twitter": {
  133. "total": 2,
  134. "successful": 2,
  135. "failed": 0
  136. }
  137. }
  138. --------------------------------------------------
  139. // TESTRESPONSE[s/"successful": 2/"successful": 1/]
  140. Here is what it looks like when one shard group failed due to pending operations:
  141. [source,js]
  142. --------------------------------------------------
  143. {
  144. "_shards": {
  145. "total": 4,
  146. "successful": 2,
  147. "failed": 2
  148. },
  149. "twitter": {
  150. "total": 4,
  151. "successful": 2,
  152. "failed": 2,
  153. "failures": [
  154. {
  155. "shard": 1,
  156. "reason": "[2] ongoing operations on primary"
  157. }
  158. ]
  159. }
  160. }
  161. --------------------------------------------------
  162. // NOTCONSOLE
  163. NOTE: The above error is shown when the synced flush fails due to concurrent indexing operations. The HTTP
  164. status code in that case will be `409 CONFLICT`.
  165. Sometimes the failures are specific to a shard copy. The copies that failed will not be eligible for
  166. fast recovery but those that succeeded still will be. This case is reported as follows:
  167. [source,js]
  168. --------------------------------------------------
  169. {
  170. "_shards": {
  171. "total": 4,
  172. "successful": 1,
  173. "failed": 1
  174. },
  175. "twitter": {
  176. "total": 4,
  177. "successful": 3,
  178. "failed": 1,
  179. "failures": [
  180. {
  181. "shard": 1,
  182. "reason": "unexpected error",
  183. "routing": {
  184. "state": "STARTED",
  185. "primary": false,
  186. "node": "SZNr2J_ORxKTLUCydGX4zA",
  187. "relocating_node": null,
  188. "shard": 1,
  189. "index": "twitter"
  190. }
  191. }
  192. ]
  193. }
  194. }
  195. --------------------------------------------------
  196. // NOTCONSOLE
  197. NOTE: When a shard copy fails to sync-flush, the HTTP status code returned will be `409 CONFLICT`.
  198. The synced flush API can be applied to more than one index with a single call,
  199. or even on `_all` the indices.
  200. [source,js]
  201. --------------------------------------------------
  202. POST kimchy,elasticsearch/_flush/synced
  203. POST _flush/synced
  204. --------------------------------------------------
  205. // CONSOLE