Insert index elasticsearch java batch operation

1. Therefore, a single insert
// first parameter: the name index; second parameter: index type; third parameter: (modify the same data id, the default is a random string) index ID
IndexResponse indexResponse = client.prepareIndex . ( "twitter", "json ", "1") setSource (json) .get ();

2. Insert Batch
BulkRequestBuilder bulkRequest = client.prepareBulk ();

IndexRequest request = client.prepareIndex("twitter", "json","1").setSource(json).request();
IndexRequest request2 = client.prepareIndex("twitter", "json","2").setSource(json2).request();

bulkRequest.add(request);
bulkRequest.add(request2);

bulkRequest.execute().actionGet();

Guess you like

Origin www.cnblogs.com/gavinYang/p/11200193.html