First, install the plug-in
To delete all documents under one type of an index, this is equivalent to emptying the table operation in a relational database . Check out some of the information can be removed through the Delete-by-query plugin, first install the Delete-by-query plugin using the plugin manager:
sudo bin/plugin install Delete-by-query
Offline mode similar to head, decompression placed under the elasticsearch/plugins/can be.
When a cluster has multiple nodes, each node needs to be installed and restarted.
If you want to remove a plug-in, you can execute the following command:
sudo bin/plugin remove delete-by-query
second, import jar package
Guide Package: elasticsearch-2.3.3/plugins/delete-by-query/delete-by-query-2.3.3.jar
add to the project path.
third, modify the way the client is created
Client client = Transportclient.builder () . Settings (Settings) . Addplugin (deletebyqueryplugin. class ) . Build () . addtransportaddress (new inetsockettransportaddress ( Inetaddress.getbyname ("192.168.0.224"9300));
Added the Addplugin line.
Iv. Delete all documents under one type
To delete all documents under Blog/article:
1. Command-line mode
" Http://192.168.0.224:9200/blog/article/_query " ' {"query": { "match_all": {} }}'
2.java API
Import Org.elasticsearch.action.deletebyquery.deletebyqueryaction;import Org.elasticsearch.action.deletebyquery.deletebyqueryrequestbuilder;import Org.elasticsearch.action.deletebyquery.deletebyqueryresponse;import Org.elasticsearch.plugin.deletebyquery.DeleteByQueryPlugin; String Deletebyquery="{\ "query\": {\ "match_all\": {}}}";D eletebyqueryresponse Response=Newdeletebyqueryrequestbuilder (client, deletebyqueryaction.instance) . SetIndices ("Blog"). Settypes ("article"). SetSource (Deletebyquery). Execute () . Actionget ();
from:http://blog.csdn.net/napoay/article/details/52038619
Elasticsearch Java Api--deletebyquery