Flush

Introduced 1.0

The Flush API stores all in-memory operations to segments on disk. Operations flushed to an index segment are no longer needed in transaction logs during a cluster restart because these operations are now stored in the Lucene index.

OpenSearch automatically performs flushes in the background based on conditions like transaction log size, which is controlled by the index.translog.flush_threshold_size setting. Use the Flush API sparingly, for example, for manual restarts or to free up memory.

Path and HTTP methods

The Flush API supports the following paths:

  1. GET /_flush
  2. POST /_flush
  3. GET /{index}/_flush
  4. POST /{index}/_flush

Path parameters

The following table lists the available path parameters. All path parameters are optional.

ParameterData typeDescription
<index>StringA comma-separated list of indexes, data streams, or index aliases to which the operation is applied. Supports wildcard expressions (). Use _all or to specify all indexes and data streams in a cluster.

Query parameters

All parameters are optional.

ParameterData typeDescription
allow_no_indicesBooleanWhen false, the request returns an error if any wildcard expression or index alias targets any closed or missing indexes. Default is true.
expand_wildcardsStringSpecifies the types of indexes to which wildcard expressions can expand. Supports comma-separated values. Valid values are:
- all: Expand to all open and closed indexes, including hidden indexes.
- open: Expand to open indexes.
- closed: Expand to closed indexes.
- hidden: Include hidden indexes when expanding. Must be combined with open, closed, or both.
- none: Do not accept wildcard expressions.
Default is open.
forceBooleanWhen true, forces a flush to occur even when no changes to the index exist in-memory. Default is true.
ignore_unavailableBooleanWhen true, OpenSearch ignores missing or closed indexes. If false, OpenSearch returns an error if the force merge operation encounters missing or closed indexes. Default is false.
wait_if_ongoingBooleanWhen true, the Flush API does not run while another flush request is active. When false, OpenSearch returns an error if another flush request is active. Default is true.

Example requests

Flush a specific index

The following example flushes an index named shakespeare:

  1. POST /shakespeare/_flush

copy

Flush all indexes

The following example flushes all indexes in a cluster:

  1. POST /_flush

copy

Example response

OpenSearch responds with the number of shards that acknowledged the flush request, the number of shards that completed the request, and the number of shards that failed:

  1. {
  2. "_shards": {
  3. "total": 10,
  4. "successful": 10,
  5. "failed": 0
  6. }
  7. }