Open / Close Index APIedit

The open and close index APIs allow to close an index, and later on opening it. A closed index has almost no overhead on the cluster (except for maintaining its metadata), and is blocked for read/write operations. A closed index can be opened which will then go through the normal recovery process.

To reduce the risk of data loss, avoid keeping closed indices in your cluster for long periods of time. When a node leaves your cluster, Elasticsearch does not rebuild the lost copies of the shards in any closed indices. As you replace the nodes in your cluster over time you will gradually lose the shard data for any closed indices.

In managed environments such as Elastic Cloud nodes may be automatically replaced at any time, which will result in the loss of data held in closed indices. You should not close any indices if your cluster is running in such a a managed environment.

If you want to reduce the overhead of an index while keeping it available for occasional searches, freeze the index instead. If you want to store an index outside of the cluster, use a snapshot.

The REST endpoint is /{index}/_close and /{index}/_open. For example:

POST /my_index/_close

POST /my_index/_open

It is possible to open and close multiple indices. An error will be thrown if the request explicitly refers to a missing index. This behaviour can be disabled using the ignore_unavailable=true parameter.

All indices can be opened or closed at once using _all as the index name or specifying patterns that identify them all (e.g. *).

Identifying indices via wildcards or _all can be disabled by setting the action.destructive_requires_name flag in the config file to true. This setting can also be changed via the cluster update settings api.

Closed indices consume a significant amount of disk-space which can cause problems in managed environments. Closed indices are enabled by default. You can disable closed indices by setting cluster.indices.close.enable to false using the cluster settings API.

Closed indices are ignored by many APIs. For instance, the shards of a closed index are not included in the output of the cat shards API.

Wait For Active Shardsedit

Because opening an index allocates its shards, the wait_for_active_shards setting on index creation applies to the index opening action as well. The default value for the wait_for_active_shards setting on the open index API is 0, which means that the command won’t wait for the shards to be allocated.