Elasticsearch Java API Batch processing

Source: Internet
Author: User

Original address: http://blog.csdn.net/u012116196/article/details/51754845


The Bulkprocessor class provides a simple interface for automatic flushing of bulk operations based on the number or size of requests, or at a given period.

Using it, you first create a Bulkprocessor instance:[Java]  View Plain  copy import org.elasticsearch.action.bulk.backoffpolicy;   import  org.elasticsearch.action.bulk.bulkprocessor;   Import org.elasticsearch.common.unit.bytesizeunit ;   import org.elasticsearch.common.unit.bytesizevalue;   import  org.elasticsearch.common.unit.timevalue;      bulkprocessor bulkprocessor =  Bulkprocessor.builder (           client,  //<1 >           new bulkprocessor.listener ()  {                 @Override                 public void beforebulk (long  executionid,                      &nbsP;                bulkrequest  request)  { ... } //<2>                    @Override                 public void afterbulk (long executionid,                                       bulkrequest request,                                        Bulkresponse response)  { ... } //<3>                    @Override                 public void afterbulk (long executionid,                                       BulkRequest request,                                      throwable  failure)  { ... } //<4>           &NBSP})            .setbulkactions (10000)  //<5>            .setbulksize (New bytesizevalue (1,  BYTESIZEUNIT.GB))  //<6>           .setflushinterval (TimeValue.timeValueSeconds ( 5)  //<7>           .setconcurrentrequests (1)  //<8>           .setbackoffpolicy (               backoffpolicy.exponentialbackoff ( Timevalue.timevaluemillis,  3)  //<9>            .build ();  

Add your Elasticsearch customer

Executed before this method is called. For example you can see Numberofactions request.numberofactions ()

Call this method after bulk execution. For example, you can check if there are some failed requests

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.