# Delete documents of an index older than 7 days

**URL:** <https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056>\
**Category:** Elasticsearch\
**Created:** [September 11, 2018, 6:38am UTC](https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056 "2018-09-11T06:38:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 11, 2018, 6:38am UTC](https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056/1 "2018-09-11T06:38:03Z")

</div>

I want to delete documents from my index ''index\_name" which are older than 7 days.  
The field I want to use is not @timestamp and is another field "date" in that index.

I am not sure of the DELETE QUERY.

Please help

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [September 11, 2018, 7:05am UTC](https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056/2 "2018-09-11T07:05:22Z")

</div>

you can use the delete query along with time range

---

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 11, 2018, 7:28am UTC](https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056/3 "2018-09-11T07:28:13Z")

</div>

![20180911_125212](https://us1.discourse-cdn.com/elastic/original/3X/1/b/1b50b2ef3d1b7336abaa6b47183e6ae37d500c97.jpeg)

I am using the query in screenshot. The only problem is date less than : now-5 is deleting documents as now-4. Suppose if I run it today 11th Sept it is deleting docs of 6th September too.

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [September 11, 2018, 7:30am UTC](https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056/4 "2018-09-11T07:30:23Z")

</div>

make it now-6d and try to run  
or moreover you can use it also

```auto
"range": {
    "date": {
        "gte": "2015-11-01",
        "lte": "2015-11-30"
    }
}

```

---

<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:** [October 9, 2018, 7:30am UTC](https://discuss.elastic.co/t/delete-documents-of-an-index-older-than-7-days/148056/5 "2018-10-09T07:30:30Z")

</div>

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