How to Delete an Index in Elasticsearch Using Kibana

Introduction

When you’re working with data in Elasticsearch, there will likely be situations when you need to delete an index. You might have created an index just to test out some feature, but you don’t need to keep it permanently. You might have changed your overall data structure and find that you’re no longer using a particular index, or you may have migrated your data to another system. Regardless of the exact circumstances, it’s easy to remove an Elasticsearch index with the help of Kibana. In this step-by-step guide, we’ll show you how to delete an index in Elasticsearch using Kibana. If you already have experience doing similar tasks in Kibana and prefer to dive into the sample code, feel free to skip ahead to Just The Code.

Prerequisites

Before we explain how to delete an index in Elasticsearch using Kibana, it’s important to confirm that a few prerequisites are in place. For this task, the system requirements are minimal: both Elasticsearch and Kibana need to be installed and running.

To check if Elasticsearch is running, just execute the following command in the terminal: curl http://localhost:9200/_cluster/health?pretty

You should receive output containing information about your instance of Elasticsearch. If you know that Elasticsearch is installed but you don’t receive the expected output, you may need to restart the process on your machine.

To check if Kibana is running, visit the server’s status page in a browser:

localhost:5601/status

You should see status information about your installation of Kibana.

Delete an Index in Elasticsearch Using Kibana

Use the delete index API

Let’s take a look at a simple example showing how to delete a single index using the delete index API. In this example, we’ll be deleting an index called demo_index:

DELETE /demo_index

After the delete operation occurs, you’ll receive a confirmation message like below:

{
"acknowledged" : true
}

If the delete is unsuccessful for some reason, you’d get an error response similar to the one below. In this example, the error is that the index was not found:

{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "demo_index",
"index_uuid" : "_na_",
"index" : "demo_index"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "demo_index",
"index_uuid" : "_na_",
"index" : "demo_index"
},
"status" : 404
}

When you delete an index, you’re actually deleting an entire database table full of documents, so it’s important to use this command with care to avoid losing critical data. Fortunately, the Delete Index API is simple to understand and use, so mistakes tend to be uncommon.

How to delete multiple Indices

The example shown above illustrates how to delete a single index in Elasticsearch, but it’s also possible to delete multiple indices by using wildcard expressions or a comma-delimited list. You can even delete all indices using the “*” wildcard or the keyword _all.

Our next example will show how to use a wildcard expression to delete multiple indices. First, we need to create three indices to use in this example: index1,index2, and index3.

PUT demo_index1
PUT demo_index2
PUT demo_index3

We’ll delete all three indices in a single command by using the wildcard index*. This expression matches all three of our indices because the * will match any string that follows the word index:

DELETE /demo_index*

You’ll get a confirmation that looks like the following:

{
"acknowledged" : true
}

After performing the delete command, you can confirm that the indices have been deleted by using the command below to see a list of all your indices:

GET /_cat/indices
green open kibana_sample_data_flights IYOtjvkxSq2FpH6p4eBjFA 1 0 13059 0 6.2mb 6.2mb
green open kibana_sample_data_ecommerce ulNHue7YTbWMrbIujVjNmw 1 0 4675 0 4.6mb 4.6mb
green open kibana_sample_data_logs Hla0A3biTnSeRdXA0hKhLQ 1 0 14005 0 11.1mb 11.1mb

You can see that the three indices we deleted no longer exist.

Conclusion

If you’re managing data in Elasticsearch, you’ll probably need to delete an index at some point. Fortunately, it’s quick and easy to delete an index in Elasticsearch using Kibana. With the step-by-step instructions described in this tutorial, you’ll have no trouble deleting either a single index or even multiple indices.

Just the Code

If you’re already familiar with the concept of deleting an index, here’s all the code you need to delete a single index or multiple indices:

To delete a single index:

DELETE /demo_index

To delete multiple indices with a wildcard expression:

DELETE /demo_index*

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.