|
@ -1,5 +1,7 @@
|
|
|
package com.yihu.wlyy.figure.label.storage;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.base.es.config.ElastricSearchHelper;
|
|
|
import com.yihu.wlyy.figure.label.model.SaveModel;
|
|
|
import com.yihu.wlyy.figure.label.util.ConstantUtil;
|
|
@ -18,18 +20,24 @@ public class Store2ES implements Storager {
|
|
|
|
|
|
@Override
|
|
|
public void save(List<SaveModel> modelList) {
|
|
|
List<Object> list = new ArrayList<>();
|
|
|
List<String> list = new ArrayList<>();
|
|
|
int saveCount = 0;
|
|
|
for(SaveModel saveModel:modelList){
|
|
|
list.add(saveModel);
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
try {
|
|
|
String str = objectMapper.writeValueAsString(saveModel);
|
|
|
list.add(str);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
//防止内存溢出,一次性存储10W条
|
|
|
if(list.size() >= 100000){
|
|
|
elastricSearchHelper.save(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list);
|
|
|
elastricSearchHelper.saveBulkWithCustomId(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list,"modelId");
|
|
|
list.clear();
|
|
|
saveCount ++;
|
|
|
}else if(modelList.size() - saveCount * 100000 == list.size()){
|
|
|
//剩余的零头
|
|
|
elastricSearchHelper.save(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list);
|
|
|
elastricSearchHelper.saveBulkWithCustomId(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list,"modelId");
|
|
|
}
|
|
|
}
|
|
|
}
|