flush.asciidoc 7.6 KB

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