In the 2.X version, this delete by query function was removed because the official thought it would cause some errors to install the plugin itself if needed.
Bin/plugin Install Delete-by-query
When you need to use
DELETE/Index name/type/_query{"query"needed to be emptied: {"match_all " : {}}}
Then in the 5.x version of the API is again the official back to the self-feature. That's what the new feature says.
Delete-by-query and update-by-query back to the core, formerly plug-ins, can now be used directly, but also built on the Reindex mechanism. (es1.x version is direct support, extracted as plug-in in es2.x, 5. x continue to return to direct support)
I checked the Official handbook and found that the use was different.
Official address: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete-by-query.html
That is, replacing the previous _query for _delete_by_query can achieve the goal.
Delete via header plugin
Use the head plugin to delete the specified data http: // serverhost:9200/index/type/_delete_by_query Post { "query" : { "match": { Attribute field: Property value to delete} } }
Java Code Implementation:
String index ="wareic"; Boolquerybuilder QueryBuilder=querybuilders.boolquery (); Querybuilder.must (Querybuilders.termquery ("GroupID","42023")); Bulkindexbyscrollresponse Response=DeleteByQueryAction.INSTANCE.newRequestBuilder (client). Filter (QueryBuilder). Source (in DEX).Get(); Longdeleted =response.getdeleted (); System. out. println (deleted);
Another way to achieve this:
String index ="wareic"; String type="Product"; Bulkrequestbuilder bulkrequest=Client.preparebulk (); Searchrequestbuilder Searchrequestbuilder=Client.preparesearch (Index). settypes (type);//page OutSearchrequestbuilder.setfrom (0). SetSize ( +); Boolquerybuilder QueryBuilder=querybuilders.boolquery (); Querybuilder.must (Querybuilders.termquery ("GroupID","3445")); Searchrequestbuilder.setquery (QueryBuilder); SearchResponse Response= Searchrequestbuilder.execute ().Get(); for(Searchhit hit:response.getHits ()) {String ID=Hit.getid (); Bulkrequest.add (Client.preparedelete (index, type, ID). request ()); Bulkresponse Bulkresponse= Bulkrequest.Get(); if(Bulkresponse.hasfailures ()) { for(Bulkitemresponse item:bulkResponse.getItems ()) {System. out. println (Item.getfailuremessage ()); } } Else{System. out. println ("Delete OK"); }
Article Reference address: https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.2/java-docs-delete-by-query.html
Elasticsearch 5.x Delete by Query API (conditionally deleted)