# Unable to delete data older than 7 days from elastic search

**URL:** <https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452>\
**Category:** Elasticsearch\
**Created:** [May 3, 2018, 1:08pm UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452 "2018-05-03T13:08:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratsy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratsy/32/30685_2.png) [@pratsy](https://discuss.elastic.co/u/pratsy)\
**Post date:** [May 3, 2018, 1:08pm UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/1 "2018-05-03T13:08:24Z")

</div>

Unable to delete data older than 7 days from elasticsearch using following command

```
curl -XDELETE 'http://localhost:9200/*' -d '
{
  "query": {
    "range": {
      "@timestamp": { 
        "lt": "now-7d"
      }
    }
  }
}' -H "Content-Type:application/json"

```

Don't want to use curator (so much problem with versions).

`Above command is deleting data older than current date.`

Please suggest a proper query for the same.

---

<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:** [May 3, 2018, 1:10pm UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/2 "2018-05-03T13:10:18Z")

</div>

Are you looking to delete complete indices or only some data from a set of indices? What are the problems with Curator versions you are referring to?

---

<div class="post-metadata">

**Author:** ![pratsy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratsy/32/30685_2.png) [@pratsy](https://discuss.elastic.co/u/pratsy)\
**Post date:** [May 3, 2018, 1:15pm UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/3 "2018-05-03T13:15:34Z")

</div>

@Christian_Dahlqvist Basically want to keep the retention of 7 days data. So, want to delete all data older than 7 days in elastic search.

I was using curator 5.5.1 and using the command :  
`curator --host localhost --port 9200 delete indices --older-than 7 --time-unit days --timestring %Y.%m.%d`

but getting error of `not able to find --host`

Hence looking for a query

---

<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:** [May 3, 2018, 3:23pm UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/4 "2018-05-03T15:23:11Z")

</div>

> [@pratsy](#):
>
> ```auto
> curator --host localhost --port 9200 delete indices --older-than 7 --time-unit days --timestring %Y.%m.%d
> 
> ```

This is outdated syntax which will not work with Curator 5.5.1. You must be following directions from a very old blog post. Please check the [official documentation](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/index.html) for usage of the current version.

---

<div class="post-metadata">

**Author:** ![pratsy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratsy/32/30685_2.png) [@pratsy](https://discuss.elastic.co/u/pratsy)\
**Post date:** [May 4, 2018, 6:20am UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/5 "2018-05-04T06:20:37Z")

</div>

@theuntergeek can you help me with getting the query for curator ? not able to figure out the things I need to do other than action file.

Query for : Deleting data from elastic which is older than 7 days

Thanks

---

<div class="post-metadata">

**Author:** ![pratsy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratsy/32/30685_2.png) [@pratsy](https://discuss.elastic.co/u/pratsy)\
**Post date:** [May 4, 2018, 7:21am UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/6 "2018-05-04T07:21:35Z")

</div>

Solved !

Found awesome documentation for the same.

[http://www.madhur.co.in/blog/2017/04/09/usingcuratordeleteelasticindex.html](http://www.madhur.co.in/blog/2017/04/09/usingcuratordeleteelasticindex.html)

Thanks

---

<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:** [June 1, 2018, 7:21am UTC](https://discuss.elastic.co/t/unable-to-delete-data-older-than-7-days-from-elastic-search/130452/7 "2018-06-01T07:21:45Z")

</div>

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