Elastic 5 - DeleteByQuery



I'm upgrading our Java elasticsearch layer from 2.3.3 to 5.0. Everything seems fine excepts the DeleteByQuery.

Our current code is pretty simple, we delete all documents that are having a specific parent. But sadly, I'm completely unabled to reproduce that using 5.0 DeleteByQueryRequestBuilder.

Any help would be appreciated.

QueryBuilder aQuery = QueryBuilders.termQuery("_parent", parentId);

DeleteByQueryResponse resp = new DeleteByQueryRequestBuilder(this.getElasticClient(), DeleteByQueryAction.INSTANCE)

return resp.getTotalDeleted();

Delete by Query in ES 5.0 Java Client
(Nik Everett) #2

Delete by query has moved into the reindex module so it can share code with the reindex feature added in 2.3. It shares the same superclass for its request objects as reindex and update-by-query.

I think it looks something like:

DeleteByQueryRequestBuilder req = new DeleteByQueryRequestBuilder(this.getElasticClient(), DeleteByQueryAction.INSTANCE);
DeleteByQueryResponse resp = req.get();


Thanks a lot. My tests were around your solution except that I didn't find that magical .source() to apply everything to it.

(Nik Everett) #4

Sorry! I wrote the API for reindex first and everything else kind of flowed from it. .source() in this case means "the source of the documents to index". Then we ported delete-by-query so it could take advantage of throttling and the rest of the infrastructure coming in to reindex. In 5.1 it'll be parallelizable by setting slices, for example. But that means the API changed totally. Sorry!


No need to be sorry, I got my answer quicker than the time I spent to look for it myself. That was an easier update than going from 1.x to 2.x.

(system) #6

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