# Delete all children from all documents in a parent-child mapping

**URL:** <https://discuss.elastic.co/t/delete-all-children-from-all-documents-in-a-parent-child-mapping/81185>\
**Category:** Elasticsearch\
**Created:** [April 4, 2017, 4:52pm UTC](https://discuss.elastic.co/t/delete-all-children-from-all-documents-in-a-parent-child-mapping/81185 "2017-04-04T16:52:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![francois](https://avatars.discourse-cdn.com/v4/letter/f/77aa72/32.png) [@francois](https://discuss.elastic.co/u/francois)\
**Post date:** [April 4, 2017, 4:52pm UTC](https://discuss.elastic.co/t/delete-all-children-from-all-documents-in-a-parent-child-mapping/81185/1 "2017-04-04T16:52:42Z")

</div>

Hi All,

I have a parent / child relationship.

Parents are books and Children are user’s comment.

book { title, author, xxx, yyy, zzz }  
usercomment { userid, comment)

I need to delete all children created by a specific user for all books, with the JAVA API,  
without iterating over all books.

I use the 5.3.0 release.

I try this code :

QueryBuilder query = termQuery("userid", "3");

DeleteByQueryRequestBuilder deleteQuery = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE);

SearchResponse response = deleteQuery.source()  
.setIndices(index)  
.setTypes(usercomment\_type)  
.setQuery(query)  
.execute().actionGet();

response.getHits().getTotalHits() returns the correct number but nothing is deleted.

What do I miss ?

Thanks for your help.

François

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 5, 2017, 7:04pm UTC](https://discuss.elastic.co/t/delete-all-children-from-all-documents-in-a-parent-child-mapping/81185/2 "2017-04-05T19:04:22Z")

</div>

`deleteQuery.source()` returns you embedded`SearchRequestBuilder`. So starting from that line you are actually building search request which you then execute and get back the search results. Take a look at [DeleteByQueryBasicTests.java](https://github.com/elastic/elasticsearch/blob/3136ed1490e41b4c82b8ee05ff2d224e113ef1b8/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java) to see working examples.

---

<div class="post-metadata">

**Author:** ![francois](https://avatars.discourse-cdn.com/v4/letter/f/77aa72/32.png) [@francois](https://discuss.elastic.co/u/francois)\
**Post date:** [April 6, 2017, 7:35am UTC](https://discuss.elastic.co/t/delete-all-children-from-all-documents-in-a-parent-child-mapping/81185/3 "2017-04-06T07:35:46Z")

</div>

Thanks !

François

---

<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:** [May 4, 2017, 7:36am UTC](https://discuss.elastic.co/t/delete-all-children-from-all-documents-in-a-parent-child-mapping/81185/4 "2017-05-04T07:36:12Z")

</div>

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