Elastic Search

Elasticsearch Freeze and Unfreeze Index

Freezing an index allows you to close the index within a cluster. Instead of deleting an index, freezing allows you to disable the index from the cluster temporarily. This enables you to reduce the overhead induced by the index on the cluster and improve memory usage.

This article will teach you how to freeze and unfreeze an index using the Freeze and Unfreeze Index APIs.

Note that the freeze and unfreeze API have been removed due to memory improvements in Elasticsearch version 8.0 and above. Hence, this tutorial will only work on Elasticsearch version 7.x and below.

Elasticsearch Freeze Index API

To freeze an existing index, we use the freeze index API. The request syntax is as shown below:

POST /<index>/_freeze

Note that the freeze API requires the running user to have manage privileges on the target index.

Suppose we have an index called “Netflix” we can freeze it by running the request:

curl -XPOST "http://localhost:9200/netflix/_freeze" -H "kbn-xsrf: reporting"

The index parameter is required to specify the target index.

Elasticsearch Unfreeeze Index API

Similarly, to unfreeze a frozen index, we use the Unfreeze API. The request syntax is as shown below:

POST /<index>/_unfreeze

The unfreeze API also requires you to have manage privileges on the target index. Once an index is recovered from a frozen state, Elasticseach will ensure that it performs its normal recovery process and that the index becomes writable for future requests.

We can unfreeze the Netflix index by sending a POST request to the _unfreeze API as:

curl -XPOST "http://localhost:9200/netflix/_unfreeze" -H "kbn-xsrf: reporting"

The query above should return:

#! Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release.
{
"acknowledged": true,
"shards_acknowledged": true
}

Conclusion

In this short post, you learned how you could use Elasticsearch’s freeze and unfreeze APIs to disable or enable an index temporarily.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list