# Delete old data from an Index

**URL:** <https://discuss.elastic.co/t/delete-old-data-from-an-index/92412>\
**Category:** Elasticsearch\
**Created:** [July 10, 2017, 5:04am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412 "2017-07-10T05:04:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastic-fan](https://avatars.discourse-cdn.com/v4/letter/e/779978/32.png) [@elastic-fan](https://discuss.elastic.co/u/elastic-fan)\
**Post date:** [July 10, 2017, 5:04am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/1 "2017-07-10T05:04:09Z")

</div>

Hello,  
How can i delete the old data from an index, if i create an index everyday i am facing some problems wrt shards performance , so i have only one index and i would like to delete old data. please let me know how can i achieve this

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 10, 2017, 5:07am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/2 "2017-07-10T05:07:49Z")

</div>

You need to use the delete by query plugin, but it is really inefficient.

> [@elastic-fan](#):
>
> if i create an index everyday i am facing some problems wrt shards performance

Use weekly/monthly and reduce the shard count. That'll be much cheaper than the above.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 10, 2017, 5:07am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/3 "2017-07-10T05:07:54Z")

</div>

Using time-based indices does not necessarily mean daily indices. If you have long retention period and reasonably small amounts of data coming, you can instead use monthly indices. With a single index you will need to use the [delete by query API](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/docs-delete-by-query.html), which will be more resource intensive than simply dropping an index.

---

<div class="post-metadata">

**Author:** ![elastic-fan](https://avatars.discourse-cdn.com/v4/letter/e/779978/32.png) [@elastic-fan](https://discuss.elastic.co/u/elastic-fan)\
**Post date:** [July 10, 2017, 5:21am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/4 "2017-07-10T05:21:47Z")

</div>

is there a way to automate this?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 10, 2017, 6:16am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/5 "2017-07-10T06:16:46Z")

</div>

If you are using time-based indices, you can use [Curator](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.1/index.html) to automate index management.

---

<div class="post-metadata">

**Author:** ![elastic-fan](https://avatars.discourse-cdn.com/v4/letter/e/779978/32.png) [@elastic-fan](https://discuss.elastic.co/u/elastic-fan)\
**Post date:** [July 10, 2017, 6:21am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/6 "2017-07-10T06:21:48Z")

</div>

i dont prefer using time based indices, i would like to have single index , can you please throw some light on API for clearing the data till last week?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 10, 2017, 6:25am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/7 "2017-07-10T06:25:58Z")

</div>

Using a [range query based on your timestamp field](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-range-query.html) together with the delete-by-query API should work.

---

<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 10, 2017, 6:38am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/8 "2017-07-10T06:38:47Z")

</div>

You should really follow @Christian_Dahlqvist and @warkolm advices. Time based indices is the way to go. You will also benefit from index sorting, so faster searches.

---

<div class="post-metadata">

**Author:** ![elastic-fan](https://avatars.discourse-cdn.com/v4/letter/e/779978/32.png) [@elastic-fan](https://discuss.elastic.co/u/elastic-fan)\
**Post date:** [July 10, 2017, 9:25am UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/9 "2017-07-10T09:25:19Z")

</div>

any references for deleting old data with powershell which is n days old?🙂

---

<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 10, 2017, 2:45pm UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/10 "2017-07-10T14:45:38Z")

</div>

If you are using time based indices, that should be something like:

```auto
curl -XDELETE http://localhost:9200/test-2017-06

```

(let say you have monthly indices).

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [July 10, 2017, 4:26pm UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/11 "2017-07-10T16:26:56Z")

</div>

The aforementioned Curator comes with a Windows installer, so you'd be free to use it in power-shell.

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [July 10, 2017, 4:42pm UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/12 "2017-07-10T16:42:32Z")

</div>

I should also point out it has [command-line functionality as well](https://www.elastic.co/guide/en/elasticsearch/client/curator/current/singleton-cli.html) (not just YAML-configuration), which should be just as easy to use from powershell.

---

<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:** [August 7, 2017, 4:42pm UTC](https://discuss.elastic.co/t/delete-old-data-from-an-index/92412/13 "2017-08-07T16:42:50Z")

</div>

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