# Delete

**URL:** <https://discuss.elastic.co/t/delete/72084>\
**Category:** Elasticsearch\
**Created:** [January 18, 2017, 8:38pm UTC](https://discuss.elastic.co/t/delete/72084 "2017-01-18T20:38:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)\
**Post date:** [January 18, 2017, 8:38pm UTC](https://discuss.elastic.co/t/delete/72084/1 "2017-01-18T20:38:25Z")

</div>

How the heck do I delete records form an index?  
index: test\_index

This is not working:

```
DELETE test_index/myType
{
  "query":{
    "match_all": {
      
    }
  }
}
```

---

<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:** [January 18, 2017, 8:50pm UTC](https://discuss.elastic.co/t/delete/72084/2 "2017-01-18T20:50:10Z")

</div>

Why not deleting the index in that case?

---

<div class="post-metadata">

**Author:** ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)\
**Post date:** [January 18, 2017, 9:17pm UTC](https://discuss.elastic.co/t/delete/72084/3 "2017-01-18T21:17:14Z")

</div>

I find that I have to fool around with the previously made dashboards + visualizations.  
Whenever I delete the whole index, those items become buggy, no data, errors, etc..

I tried to wait for the data to become available after re-indexing, but after a few minutes, I get impatient.

---

<div class="post-metadata">

**Author:** ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)\
**Post date:** [January 19, 2017, 2:25pm UTC](https://discuss.elastic.co/t/delete/72084/4 "2017-01-19T14:25:25Z")

</div>

This works:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html)

```
POST my_index/_delete_by_query
{
  "query":{
    "match_all": {}
  }
}
```

---

<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:** [January 19, 2017, 2:38pm UTC](https://discuss.elastic.co/t/delete/72084/5 "2017-01-19T14:38:57Z")

</div>

This is really not efficient.

```
DELETE index

```

Is much much much better.

---

<div class="post-metadata">

**Author:** ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)\
**Post date:** [January 19, 2017, 2:43pm UTC](https://discuss.elastic.co/t/delete/72084/6 "2017-01-19T14:43:18Z")

</div>

Explain, please.

---

<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:** [January 19, 2017, 6:20pm UTC](https://discuss.elastic.co/t/delete/72084/7 "2017-01-19T18:20:11Z")

</div>

The delete by query will have to write new segments telling Lucene that docs X,Y,Z have been removed. Well, all docs basically.  
Then at some point a merge segments operation will happen and those files will be removed.

Look at the disk space, then try the delete by query and just after, look at the disk space.

Removing an index will immediately remove all files "like a rm -r". No merge of segments. Space is immediately released.

---

<div class="post-metadata">

**Author:** ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)\
**Post date:** [January 19, 2017, 9:18pm UTC](https://discuss.elastic.co/t/delete/72084/8 "2017-01-19T21:18:54Z")

</div>

Gotcha!

I decided to go with automating the workflow.

1. Delete Index
2. Reload Index with Mapping in an external file (easier than writing in code)
3. Reload data

---

<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:** [January 19, 2017, 9:32pm UTC](https://discuss.elastic.co/t/delete/72084/9 "2017-01-19T21:32:31Z")

</div>

Definitely better. Note that you can use aliases so your users won't ever notice that you reindexed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 16, 2017, 9:32pm UTC](https://discuss.elastic.co/t/delete/72084/10 "2017-02-16T21:32:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
