close and open elasticsearch indexes2 min read

Prabhin Prabharkaran Administrator
DevOps Engineer

He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!

follow me

Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. Elasticsearch is developed in Java.

In this document, we will show how to open and close the indexes. Here is one of the uses where you might need to open and close the indexes. let’s assume that you are restoring elasticsearch snapshots from the repository using a curator. If you don’t know how to backup and restore elasticsearch data, then check out this link. how to backup and restore elasticsearch indexes using curator

So during restoration, we have to ensure that the restoring index is opened. If it is opened Elasticsearch won’t allow writing data to the indexes. So we need to close it. and Once the data is restored we have to make sure that the same index needs to be opened otherwise the data cannot read from the index.

I hope you understand this simple use case.

Now let’s see how to perform the same.

Note:  Expected output for all the command is acknowledged: true

 

Close a particular index.

curl -XPOST "localhost:9200/nginx-access-log/_close"

The above command will close the index named nginx-access-logs

The expected output is acknowledged: true

Open a particular index

curl -XPOST "localhost:9200/nginx-access-log/_open"

The above command will open the index named nginx-access-logs

close indexes based on pattern

curl -XPOST "localhost:9200/nginx-*/_close"

this closes the indexes which have the pattern nginx-*

open indexes based on pattern

curl -XPOST "localhost:9200/nginx-*/_open"

this opens the indexes which have the pattern nginx-*

Close all the indexes in the Elasticsearch

curl -XPOST "localhost:9200/_all/_close"

Open all the indexes in the Elasticsearch

curl -XPOST "localhost:9200/_all/_open"

 

Delete the indexes

curl -XDELETE localhost:9200/myapp

Delete the indexes based on pattern

curl -XDELETE localhost:9200/myapp*

© 2020, Techrunnr. All rights reserved.

#1
#2
#3
Questions Answered
Articles Written
Overall Points

Leave a Reply