# Deleting first n documents from index

**URL:** https://discuss.elastic.co/t/deleting-first-n-documents-from-index/11982
**Category:** Elasticsearch
**Created:** [May 15, 2013, 9:21pm UTC](https://discuss.elastic.co/t/deleting-first-n-documents-from-index/11982 "2013-05-15T21:21:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jim\_Flim](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@Jim\_Flim](https://discuss.elastic.co/u/Jim_Flim)
#### Post date: [May 15, 2013, 9:21pm UTC](https://discuss.elastic.co/t/deleting-first-n-documents-from-index/11982/1 "2013-05-15T21:21:08Z")

</div>

Hey, this is a pretty simple question but after much searching I'm still  
stumped. Basically I want to create a delete by query that deletes the  
first n documents from a given index. The only thing I found relating to  
restricting the size were the from/size parameters  
[http://www.elasticsearch.org/guide/reference/api/search/from-size/](http://www.elasticsearch.org/guide/reference/api/search/from-size/) but as  
far as I'm aware that isn't compatible with the query DSL. I also found the  
_limit_ query but that only limits the documents to retrieve per shard. I'm  
probably missing something really obvious but I'm completely stumped.

Any help would be greatly appreciated, Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)
#### Post date: [May 15, 2013, 9:23pm UTC](https://discuss.elastic.co/t/deleting-first-n-documents-from-index/11982/2 "2013-05-15T21:23:58Z")

</div>

Hey,

a delete by query will delete all documents that match the query not just  
the top N results. How do you define the first N? are they the oldest docs  
in the index? maybe you can give some details so we can help better.

simon

On Wednesday, May 15, 2013 11:21:08 PM UTC+2, Jim Flim wrote:

> Hey, this is a pretty simple question but after much searching I'm still  
> stumped. Basically I want to create a delete by query that deletes the  
> first n documents from a given index. The only thing I found relating to  
> restricting the size were the from/size parameters  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/from-size/) but as  
> far as I'm aware that isn't compatible with the query DSL. I also found the  
> _limit_ query but that only limits the documents to retrieve per shard.  
> I'm probably missing something really obvious but I'm completely stumped.
> 
> Any help would be greatly appreciated, Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jim\_Flim](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@Jim\_Flim](https://discuss.elastic.co/u/Jim_Flim)
#### Post date: [May 15, 2013, 9:38pm UTC](https://discuss.elastic.co/t/deleting-first-n-documents-from-index/11982/3 "2013-05-15T21:38:51Z")

</div>

Yea basically I want a query that matches all docs of an index and deletes  
the oldest n documents  
On May 15, 2013 5:24 PM, "simonw" [simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com) wrote:

> Hey,
> 
> a delete by query will delete all documents that match the query not just  
> the top N results. How do you define the first N? are they the oldest docs  
> in the index? maybe you can give some details so we can help better.
> 
> simon
> 
> On Wednesday, May 15, 2013 11:21:08 PM UTC+2, Jim Flim wrote:
> 
> > Hey, this is a pretty simple question but after much searching I'm still  
> > stumped. Basically I want to create a delete by query that deletes the  
> > first n documents from a given index. The only thing I found relating to  
> > restricting the size were the from/size parameters [http://www](http://www).\*\*  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/api/search/from-** size/)[http://www.elasticsearch.org/guide/reference/api/search/from-size/](http://www.elasticsearch.org/guide/reference/api/search/from-size/) but  
> > as far as I'm aware that isn't compatible with the query DSL. I also found  
> > the _limit_ query but that only limits the documents to retrieve per  
> > shard. I'm probably missing something really obvious but I'm completely  
> > stumped.
> > 
> > Any help would be greatly appreciated, Thanks
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/Ir8WBt\_lUjc/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/Ir8WBt_lUjc/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:36am UTC](https://discuss.elastic.co/t/deleting-first-n-documents-from-index/11982/4 "2017-07-06T02:36:27Z")

</div>


