# Delete oldest X documents from index

**URL:** https://discuss.elastic.co/t/delete-oldest-x-documents-from-index/18704
**Category:** Elasticsearch
**Created:** [July 16, 2014, 4:36pm UTC](https://discuss.elastic.co/t/delete-oldest-x-documents-from-index/18704 "2014-07-16T16:36:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ophir\_Michaeli](https://avatars.discourse-cdn.com/v4/letter/o/9f8e36/32.png) [@Ophir\_Michaeli](https://discuss.elastic.co/u/Ophir_Michaeli)
#### Post date: [July 16, 2014, 4:36pm UTC](https://discuss.elastic.co/t/delete-oldest-x-documents-from-index/18704/1 "2014-07-16T16:36:59Z")

</div>

Hi all,

I want to delete the oldest X docs from my elasticsearch index.  
How do I do that?

Thanks, Ophir

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/04e6e4b0-2498-4be8-893d-01059e6f1a69%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/04e6e4b0-2498-4be8-893d-01059e6f1a69%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![David\_Smith\_2](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@David\_Smith\_2](https://discuss.elastic.co/u/David_Smith_2)
#### Post date: [July 16, 2014, 5:26pm UTC](https://discuss.elastic.co/t/delete-oldest-x-documents-from-index/18704/2 "2014-07-16T17:26:47Z")

</div>

You could add datetime field to your document and order by that in  
ascending order and get the first X document id's. And then delete the  
documents by id.

While that's the solution to the question you asked, it might be better to  
re-think your problem so that you don't have to delete the oldest X  
documents. Have you considered whether your problem fits into the  
time-series index model? If it does, then you can just delete the oldest  
day (or whatever time period). Take a look at this  
video: [http://www.elasticsearch.org/videos/big-data-search-and-analytics/](http://www.elasticsearch.org/videos/big-data-search-and-analytics/)  
(about 21:15 minute mark).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e215f898-562f-4fa1-9052-c0130ab6ee8c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e215f898-562f-4fa1-9052-c0130ab6ee8c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 1:15am UTC](https://discuss.elastic.co/t/delete-oldest-x-documents-from-index/18704/3 "2017-07-06T01:15:24Z")

</div>


