|
@ -2,6 +2,7 @@ package com.yihu.wlyy.statistics.etl.save.es;
|
|
|
|
|
|
import com.yihu.wlyy.statistics.vo.SaveModel;
|
|
|
import io.searchbox.client.JestClient;
|
|
|
import io.searchbox.client.JestResult;
|
|
|
import io.searchbox.core.Bulk;
|
|
|
import io.searchbox.core.BulkResult;
|
|
|
import io.searchbox.core.Index;
|
|
@ -39,15 +40,23 @@ public class ElastricSearchSave {
|
|
|
//得到链接
|
|
|
JestClient jestClient = elasticFactory.getJestClient();
|
|
|
|
|
|
int success = 0;
|
|
|
int error = 0;
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
for (SaveModel obj : sms) {
|
|
|
obj.setCreateTime(new Date());
|
|
|
Index index = new Index.Builder(obj).build();
|
|
|
bulk.addAction(index);
|
|
|
try {
|
|
|
obj.setCreateTime(new Date());
|
|
|
Index index = new Index.Builder(obj).build();
|
|
|
bulk.addAction(index);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
logger.info("save data count:" + sms.size());
|
|
|
logger.info("save flag:" + br.isSucceeded());
|
|
|
logger.info("update flag:" + br.isSucceeded());
|
|
|
logger.info("update success:" + success);
|
|
|
logger.info("update error:" + error);
|
|
|
return br.isSucceeded();
|
|
|
} catch (Exception e) {
|
|
|
logger.error(" save error :" + e.getMessage());
|
|
@ -61,16 +70,39 @@ public class ElastricSearchSave {
|
|
|
//得到链接
|
|
|
JestClient jestClient = elasticFactory.getJestClient();
|
|
|
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
int success = 0;
|
|
|
int error = 0;
|
|
|
boolean isSuccessed = true;
|
|
|
// Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
// for (SaveModel obj : sms) {
|
|
|
// try {
|
|
|
// obj.setCreateTime(new Date());
|
|
|
// Update index = new Update.Builder(obj).index(esIndex).type(esType).id(obj.getId()).build();
|
|
|
// bulk.addAction(index);
|
|
|
// success++;
|
|
|
// } catch (Exception e) {
|
|
|
// error++;
|
|
|
// }
|
|
|
// }
|
|
|
for (SaveModel obj : sms) {
|
|
|
obj.setCreateTime(new Date());
|
|
|
Update index = new Update.Builder(obj).build();
|
|
|
bulk.addAction(index);
|
|
|
try {
|
|
|
obj.setCreateTime(new Date());
|
|
|
Update index = new Update.Builder(obj).index(esIndex).type(esType).id(obj.getId()).build();
|
|
|
JestResult result = jestClient.execute(index);
|
|
|
if (result.isSucceeded()) {
|
|
|
success++;
|
|
|
} else {
|
|
|
error++;
|
|
|
isSuccessed = false;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
error++;
|
|
|
isSuccessed = false;
|
|
|
}
|
|
|
}
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
logger.info("update data count:" + sms.size());
|
|
|
logger.info("update flag:" + br.isSucceeded());
|
|
|
return br.isSucceeded();
|
|
|
logger.info("update success:" + success);
|
|
|
logger.info("update error:" + error);
|
|
|
return isSuccessed;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(" update error :" + e.getMessage());
|
|
|
}
|