list存放着40萬條jsonObject數據
@Autowired
@Qualifier(“esHighLevelClient”)
private RestHighLevelClient client;
int i=0;
if(list.size()%10000==0){
i=list.size()/10000;
}else{
i=list.size()/10000+1;
}
for(int j=0;j<i;j++){
//分批插入 1萬條插入
List<JSONObject> collect = list.stream().skip(j * 10000).limit(10000).collect(Collectors.toList());
System.out.println(collect.size()+":::::"+j);
BulkRequest request = new BulkRequest();
request.timeout(TimeValue.timeValueMillis(5000));
for(JSONObject json:collect){
try {
request.add(new IndexRequest(themeType).id(json.get("id").toString()).source(json.toString(), XContentType.JSON));
} catch (Exception e) {
}
}
client.bulk(request, RequestOptions.DEFAULT);
}