Distributed search elasticsearch Java API (6) -- batch add and delete Indexes

Source: Internet
Author: User
Tags elastic search

Elasticsearch supports batch addition or deletion of index documents. In Java APIs, bulkrequestbuilder is constructed, batch index/delete requests are added to bulkrequestbuilder, and bulkrequestbuilder is executed. The following is an example:

Import static Org. elasticsearch. common. xcontent. xcontentfactory. *; bulkrequestbuilder bulkrequest = client. preparebulk (); bulkrequest. add (client. prepareindex ("Twitter", "tweet", "1 "). setsource (jsonbuilder (). startobject (). field ("user", "kimchy "). field ("postdate", new date ()). field ("message", "trying out elastic search "). endobject (); bulkrequest. add (client. prepareindex ("Twitter", "tweet", "2 "). setsource (jsonbuilder (). startobject (). field ("user", "kimchy "). field ("postdate", new date ()). field ("message", "another post "). endobject (); bulkresponse = bulkrequest.exe cute (). actionget (); If (bulkresponse. hasfailures () {// handle error}

Add index Operation Reference: http://blog.csdn.net/laigood12345/article/details/7460544

Index deletion operation reference: http://blog.csdn.net/laigood12345/article/details/7460602

References: http://www.elasticsearch.org/guide/reference/java-api/bulk.html

Address: http://blog.csdn.net/laigood12345/article/details/7606079

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.