[[indices-flush]]
=== Flush

Flushing an index is the process of making sure that any data that is currently
only stored in the <<index-modules-translog,transaction log>> is also
permanently stored in the Lucene index. When restarting, {es} replays any
unflushed operations from the transaction log into the Lucene index to bring it
back into the state that it was in before the restart. {es} automatically
triggers flushes as needed, using heuristics that trade off the size of the
unflushed transaction log against the cost of performing each flush.

Once each operation has been flushed it is permanently stored in the Lucene
index. This may mean that there is no need to maintain an additional copy of it
in the transaction log, unless <<index-modules-translog-retention,it is retained
for some other reason>>. The transaction log is made up of multiple files,
called _generations_, and {es} will delete any generation files once they are no
longer needed, freeing up disk space.

It is also possible to trigger a flush on one or more indices using the flush
API, although it is rare for users to need to call this API directly. If you
call the flush API after indexing some documents then a successful response
indicates that {es} has flushed all the documents that were indexed before the
flush API was called.

[source,console]
--------------------------------------------------
POST twitter/_flush
--------------------------------------------------
// TEST[setup:twitter]

[float]
[[flush-parameters]]
==== Request Parameters

The flush API accepts the following request parameters:

[horizontal]
`wait_if_ongoing`:: If set to `true` the flush operation will block until the
flush can be executed if another flush operation is already executing. If set to
`false` then an exception will be thrown on the shard level if another flush
operation is already running. Defaults to `true`.

`force`:: Whether a flush should be forced even if it is not necessarily needed
i.e. if no changes will be committed to the index. This can be used to force
the generation number of the transaction log to be incremented even if no
uncommitted changes are present. This parameter should be considered internal.

[float]
[[flush-multi-index]]
==== Multi Index

The flush API can be applied to more than one index with a single call, or even
on `_all` the indices.

[source,console]
--------------------------------------------------
POST kimchy,elasticsearch/_flush

POST _flush
--------------------------------------------------
// TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]


[float]
[[synced-flush-api]]
==== Synced Flush

See <<indices-synced-flush-api>>.
