0
0
Elasticsearchquery~5 mins

Deleting and closing indexes in Elasticsearch

Choose your learning style9 modes available
Introduction

Deleting and closing indexes helps manage storage and performance in Elasticsearch. Deleting removes data you no longer need, while closing temporarily frees resources without losing data.

You want to permanently remove old or unused data to save disk space.
You need to temporarily disable an index to reduce resource use but keep data for later.
You want to clean up test or development indexes after finishing work.
You want to improve cluster performance by closing rarely used indexes.
You want to prepare an index for reindexing or maintenance.
Syntax
Elasticsearch
DELETE /index_name

POST /index_name/_close

POST /index_name/_open

Use DELETE to remove an index completely.

Use _close to close an index without deleting data.

Use _open to reopen a closed index.

Examples
This deletes the index named my-old-index permanently.
Elasticsearch
DELETE /my-old-index
This closes the index my-index, freeing resources but keeping data.
Elasticsearch
POST /my-index/_close
This reopens the previously closed index my-index so it can be searched again.
Elasticsearch
POST /my-index/_open
Sample Program

This example shows how to delete (test-old-index), close, and open (test-index) indexes using Elasticsearch REST API calls.

Elasticsearch
# Delete an index
DELETE /test-old-index

# Close an index
POST /test-index/_close

# Open the closed index
POST /test-index/_open
OutputSuccess
Important Notes

Deleting an index is permanent and cannot be undone.

Closed indexes do not use resources but cannot be searched until reopened.

Always check if an index exists before deleting or closing to avoid errors.

Summary

Deleting removes an index and its data permanently.

Closing an index frees resources but keeps data safe.

Use _open to reopen closed indexes when needed.