Let’s dive in!
What Is a Closed Index in Elasticsearch?
A closed index refers to a normal index that is in a closed state. Elasticsearch blocks the read and write operations on a closed index. It also prevents the other operations that an opened index allows. For example, you can’t create aliases, searching, etc.
Closing an index is an excellent method of reducing the cluster overhead as closed indices do not main internal data structures.
However, closed indices do take up disk spaces. Therefore, if you are looking to reduce a disk usage, consider the other techniques such as moving an index, etc.
It is also good to ensure that the index that you wish to close exists in the cluster and no clients are performing any actions during the close operation.
Request Syntax
The following command shows the syntax for using the close index API:
The request accepts the following path parameters:
<index> – An index name or a list of indices as a comma-separated list. You can also use the wildcard characters. This may require the action.desctructive.requires_name set to false.
Example
The following example shows how to use the Elasticsearch close API to close an index under the name “Netflix”.
The previous request should return an output as follows:
"acknowledged": true,
"shards_acknowledged": true,
"indices": {
"netflix": {
"closed": true
}
}
}
You can check if the index is closed by running the following query:
Since the index is closed, Elasticsearch blocks the read request but provides a reason as shown in the following:
"error": {
"root_cause": [
{
"type": "index_closed_exception",
"reason": "closed",
"index_uuid": "zSe-VsUYTfeEc8NVmqkLcw",
"index": "netflix"
}
],
"type": "index_closed_exception",
"reason": "closed",
"index_uuid": "zSe-VsUYTfeEc8NVmqkLcw",
"index": "netflix"
},
"status": 400
}
Conclusion
In this post, we explored the basics of working with the Elasticsearch close index API which allows you to put an open index to a closed state. Explore the other documents for more information.
Thanks for reading!