# Remove old data from database

**URL:** <https://discuss.elastic.co/t/remove-old-data-from-database/222374>\
**Category:** Logstash\
**Created:** [March 5, 2020, 9:22pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374 "2020-03-05T21:22:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![coi6644](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/coi6644/32/63918_2.png) [@coi6644](https://discuss.elastic.co/u/coi6644)\
**Post date:** [March 5, 2020, 9:22pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/1 "2020-03-05T21:22:44Z")

</div>

Hi,  
How can I remove data older from 12 months from database? I have a ELK+Elastiflow to collect logs from some equipments, but I need to do a cleanup of records older than 12 monts.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [March 5, 2020, 9:33pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/2 "2020-03-05T21:33:01Z")

</div>

how is your index created. one index per day, per month or everything is in one index?

if you have seperate index then it is easy you can drop them.  
if everything is in one index then it is going to be pain

```
POST index-name/_delete_by_query?conflicts=proceed
{
  "query": {
    "range": {
      "date_field_name": {
        "gte": "02-02-2020",
        "lte": "02-19-2020",
        "format": "MM-dd-yyyy"
      }
    }
  }
}

```

This will be painfully slow

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [March 5, 2020, 9:34pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/3 "2020-03-05T21:34:31Z")

</div>

just dropping index from command line

curl -u username:passwd -X DELETE "hostname:9200/index-name?pretty"

---

<div class="post-metadata">

**Author:** ![coi6644](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/coi6644/32/63918_2.png) [@coi6644](https://discuss.elastic.co/u/coi6644)\
**Post date:** [March 5, 2020, 9:44pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/4 "2020-03-05T21:44:09Z")

</div>

How can I confirm how and where my indexes was created?

---

<div class="post-metadata">

**Author:** ![coi6644](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/coi6644/32/63918_2.png) [@coi6644](https://discuss.elastic.co/u/coi6644)\
**Post date:** [March 5, 2020, 9:51pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/5 "2020-03-05T21:51:48Z")

</div>

I ran curl -XGET -u USER [http://localhost:9200/elastiflow-\*/\_stats?pretty](http://localhost:9200/elastiflow-*/_stats?pretty) and I see some indexes by date like this:

elastiflow-3.5.2-2020.01.19  
elastiflow-3.5.2-2020.01.20  
elastiflow-3.5.2-2020.01.21

In this case, if I just run:  
curl -u username:passwd -X DELETE "hostname:9200/elastiflow-3.5.2-2020.01.20?pretty"  
curl -u username:passwd -X DELETE "hostname:9200/elastiflow-3.5.2-2020.01.21?pretty"

I delete this indexes and save disk space?

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [March 5, 2020, 9:56pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/6 "2020-03-05T21:56:35Z")

</div>

yes. you can even automate it from bash script

date --date="3 month ago" +%Y.%m.%d (will give you exact format date and you can assign this to variable and remove daily)  
2019.12.05

---

<div class="post-metadata">

**Author:** ![coi6644](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/coi6644/32/63918_2.png) [@coi6644](https://discuss.elastic.co/u/coi6644)\
**Post date:** [March 5, 2020, 9:57pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/7 "2020-03-05T21:57:03Z")

</div>

Ok. Thank you so much. Save my day.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [March 5, 2020, 9:57pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/8 "2020-03-05T21:57:35Z")

</div>

come visit the forum ask question and answer and you will learn in no time.

---

<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:** [April 2, 2020, 10:02pm UTC](https://discuss.elastic.co/t/remove-old-data-from-database/222374/9 "2020-04-02T22:02:10Z")

</div>

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