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 |