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

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

deleteQuery.source() returns you embeddedSearchRequestBuilder. 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 to see working examples.

Thanks !

François

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