# DeleteIndex doesn't delete the index folder from disk

**URL:** <https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288>\
**Category:** Elasticsearch\
**Created:** [July 12, 2016, 11:10am UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288 "2016-07-12T11:10:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 11:10am UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/1 "2016-07-12T11:10:46Z")

</div>

I am trying to delete index from elastic search using below code snippet. DeleteIndexResponse returns true, but the folder still exists in the physical location.

```auto
DeleteIndexResponse res= client.admin().indices().prepareDelete("dummyIndex").execute().actionGet();
System.out.println("Index deletion status : " + res.isAcknowledged());

```

ES no longer identifies it as index when i search from REST end point - `error": "IndexMissingException[[dummyIndex] missing]"`  
But it is not deleted from disk. Is there something i missed here?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 11:44am UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/2 "2016-07-12T11:44:20Z")

</div>

How do you check it's deleted from disk or not?

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 12:05pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/3 "2016-07-12T12:05:58Z")

</div>

When i said disk, i meant the file system directory relative to given path.data value

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 12:17pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/4 "2016-07-12T12:17:56Z")

</div>

Can you run please:

```auto
curl 127.0.0.1/_cat/indices?v
tree path/to/data/dir

```

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 12:33pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/5 "2016-07-12T12:33:06Z")

</div>

@dadoonet I ran the command and the listed indices doesn't include the deleted index ([dummyIndex] in my case)  
[http://hostname:9200/\_cat/indices?v?tree=G:\IndexDir](http://hostname:9200/_cat/indices?v?tree=G:%5CIndexDir)

green index1 1 0 2914 0 3.3mb 3.3mb  
green index2 1 0 0 0 99b 99b  
green index3 1 0 175523 0 1.2gb 1.2gb  
green index4 1 0 644 24 614.8kb 614.8kb

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 12:38pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/6 "2016-07-12T12:38:22Z")

</div>

So you're on windows?

I meant to run a `tree` command like:

```auto
tree G:\IndexDir

```

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 12:46pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/7 "2016-07-12T12:46:45Z")

</div>

yes its windows machine and i checked that the index still exists.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 12, 2016, 12:49pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/8 "2016-07-12T12:49:48Z")

</div>

Iirc removing the index from disk is asynchronous from the ack for the  
delete. Just that it is gone from the cluster state. Though I think that is  
changing a bit in 5.0 but I don't have a link handy.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 12:52pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/9 "2016-07-12T12:52:14Z")

</div>

> [@Swetha\_S](#):
>
> yes its windows machine and i checked that the index still exists.

Can you please give the output of the command?

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 12:57pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/10 "2016-07-12T12:57:11Z")

</div>

![](https://us1.discourse-cdn.com/elastic/original/2X/6/6b2168734f716f149f6dfd5c9fb2f9dd12fbedd8.png)  
Highlighted workDummy is the index which is deleted

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 1:00pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/11 "2016-07-12T13:00:08Z")

</div>

Can you print what you have in the `workdummy\0\index` dir?

There is no `_state` dir for this index. That looks strange.

Please don't use screen shots but copy and paste the output as text.

Which elasticsearch version are you using?

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 1:00pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/12 "2016-07-12T13:00:49Z")

</div>

@nik9000  
Index is getting deleted from file system as well when i run curl XDelete command from Rest Client, but when deleted using DeleteIndex java API, it is not removed from disk.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 1:03pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/13 "2016-07-12T13:03:04Z")

</div>

> [@Swetha\_S](#):
>
> Index is getting deleted from file system as well when i run curl XDelete command from Rest Client, but when deleted using DeleteIndex java API, it is not removed from disk.

This is super strange as the same code is called behind the scene.

See [https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java#L53-L53](https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java#L53-L53)

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 1:03pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/14 "2016-07-12T13:03:12Z")

</div>

@dadoonet this is the output after deleting the index using the java, do you need the file structure before index deletion? Elastic search version :1.0.2

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 1:04pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/15 "2016-07-12T13:04:14Z")

</div>

I meant: do you have remaining files in `workdummy\0\index` dir?

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 1:04pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/16 "2016-07-12T13:04:37Z")

</div>

Nope that is the end of output

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 1:07pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/17 "2016-07-12T13:07:20Z")

</div>

I have hard time to follow.

I'm not talking about the `tree` command here.

I'm asking to go into the `workdummy\0\index`, run a `dir` command so we can see if there are some files left.

BTW you are using a very old version of elasticsearch. Could you please run the same test on a new cleaned and fresh elasticsearch instance running latest 1.7?

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 12, 2016, 1:21pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/18 "2016-07-12T13:21:20Z")

</div>

yes there is a file left \_0.cfs.

> Directory of G:\IndexDir\59f92c3bcfadac7eaf599dad8eace0b3\nodes\0\indices\workdummy\0\index

> 07/12/2016 06:42 PM .  
> 07/12/2016 06:42 PM ..  
> 07/12/2016 06:42 PM 4,820 \_0.cfs  
> 1 File(s) 4,820 bytes  
> 2 Dir(s) 26,477,842,432 bytes free

Before deleting the index, do i have to call the closeIndex api- so as to remove references (if any) to the index?  
Because before deletion, i am searching with scroll api on this index.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 12, 2016, 1:47pm UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/19 "2016-07-12T13:47:38Z")

</div>

Ha! That makes more sense now.

You have to clear the scroll IMO before deleting the index. See [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-scroll.html#\_clear\_scroll\_api](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-scroll.html#_clear_scroll_api)

You don't have to close the index.

---

<div class="post-metadata">

**Author:** ![SwethaS](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SwethaS](https://discuss.elastic.co/u/SwethaS)\
**Post date:** [July 13, 2016, 6:14am UTC](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288/20 "2016-07-13T06:14:16Z")

</div>

Thanks David, after clearing the scroll, delete index deleted the folder as well.

[Next page](https://discuss.elastic.co/t/deleteindex-doesnt-delete-the-index-folder-from-disk/55288.md?page=2)
