Elasticsearch Java Api--deletebyquery

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.