# How to delete bunch of documents by list of ids

**URL:** https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511
**Category:** Elasticsearch
**Created:** [November 6, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511 "2020-11-06T09:57:19Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Alex12](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alex12](https://discuss.elastic.co/u/Alex12)
#### Post date: [November 6, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/1 "2020-11-06T09:57:19Z")

</div>

Is it possible to delete list of documents by list of documents id?

i tryed like this but it does not work at all  
`deleteAllByIdIn(List<UUID> ids);` from `ElasticsearchRepository` and it does not work at all please guid me, maybe providing a query impelemntation please?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 6, 2020, 11:17am UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/2 "2020-11-06T11:17:05Z")

</div>

Welcome!

This seems like a spring data related question and not really elasticsearch.

In elasticsearch, it's good to delete documents using the delete API or better the bulk API if you have a lot of them to delete.

---

<div class="post-metadata">

### Author: ![Alex12](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alex12](https://discuss.elastic.co/u/Alex12)
#### Post date: [November 6, 2020, 11:27am UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/3 "2020-11-06T11:27:02Z")

</div>

Thank you very much, could you please provide a solution of how to do it using bulk API?

this is how my data looks like

```auto
   {
   "id":"1234",
   "expirationDate":"17343234234",
   "paths":"http:localhost:9090",
   "work":"software dev",
   "family":{
      "baba":"jams",
      "mother":"ela"
   }
},
{
   "id":"00021",
   "expirationDate":"0123234",
   "paths":"http:localhost:8080",
   "work":"software engi",
   "family":{
      "baba":"stev",
      "mother":"hela"
   }
}

```

i need to delete all ids which its expirationDate before today`date are

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 6, 2020, 12:12pm UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/4 "2020-11-06T12:12:39Z")

</div>

Then you don't want to provide a list of ids but a query, right?

And use this API?

> **[Delete by query API | Elasticsearch Reference \[7.9\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html)**

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 6, 2020, 12:13pm UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/5 "2020-11-06T12:13:52Z")

</div>

> [@Alex12](#):
>
> i need to delete all ids which its expirationDate before today`date are

Better solution is to use time based indices and simply drop the older indices everyday.  
Which can be automated with ILM:

> **[ILM: Manage the index lifecycle | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html)**

---

<div class="post-metadata">

### Author: ![Alex12](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alex12](https://discuss.elastic.co/u/Alex12)
#### Post date: [November 6, 2020, 12:15pm UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/6 "2020-11-06T12:15:32Z")

</div>

Thanks, but i need a code using spring and not sending bunch of queries, where can i find such a code example please ? using QueryBuilder, can you provide me a code example about my case please? using QueryBuilder in springboot

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 6, 2020, 12:33pm UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/7 "2020-11-06T12:33:33Z")

</div>

Not sure it will answer your question but here is some code which uses Spring Boot (not Spring Data Elasticsearch) where I'm building

A BulkProcessor:

> <https://github.com/dadoonet/legacy-search/blob/f9ccd795304d6655b82246d3bde75816c3ee8fdb/src/main/java/fr/pilato/demo/legacysearch/dao/ElasticsearchDao.java#L71-L91>

Delete documents by id:

> <https://github.com/dadoonet/legacy-search/blob/02-bulk/src/main/java/fr/pilato/demo/legacysearch/dao/ElasticsearchDao.java#L99-L101>

---

<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: [December 8, 2020, 10:00pm UTC](https://discuss.elastic.co/t/how-to-delete-bunch-of-documents-by-list-of-ids/254511/9 "2020-12-08T22:00:05Z")

</div>

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