java es批处理

private static TransportClient client = ElasticSearch.getClientSingle();

BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
List<Map<String,Object>> data = tbInformationMapper.tbData(map);
for(int i = 0; i < data.size(); i++) {
Map<String, Object> data= data.get(i);
bulkRequestBuilder.add(client.prepareIndex(index, type, data.get("id").toString()).setSource(data));
if (i % 1000 == 0) {
bulkRequestBuilder.execute().actionGet();
bulkRequestBuilder.request().requests().clear();
}
}
if(!bulkRequestBuilder.request().requests().isEmpty()) {
bulkRequestBuilder.execute().actionGet();
bulkRequestBuilder.request().requests().clear();
}
posted @ 2020-04-03 11:20  静思,随心  阅读(345)  评论(0编辑  收藏  举报