Delete by Query in ES 5.0 Java Client


(RJIL) #1

Hello,
Just starting off with ES. Ran into problem when trying to delete the indexed documents. Seems like the Delete by Query is no longer available in ES 5.0 Java client.
How do I achieve selective delete of documents from the Index using Java client. i.e. (A query determines which all documents to be deleted).
I am running ES in embedded(local) mode for the time being. Later it will run in production mode(Client/Server).

Can anyone please help me out.


(David Pilato) #2

Is it the same question as the following?


#3

Hi. It looks the same.

Here is my code, but I haven't tried it yet. But there is no compilation error.

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

        DeleteByQueryRequestBuilder req = new DeleteByQueryRequestBuilder(this.getElasticClient(), DeleteByQueryAction.INSTANCE);
        **req.source()**                         // here is the trick
          .setIndices(index)
          .setTypes(type)
          .setRouting(idParent)
          .setQuery(aQuery);
        
        BulkIndexByScrollResponse resp = req.get();

        return resp.getDeleted();

(system) #4

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