|
@ -5,6 +5,7 @@ import io.searchbox.client.JestClient;
|
|
|
import io.searchbox.core.Bulk;
|
|
|
import io.searchbox.core.BulkResult;
|
|
|
import io.searchbox.core.Index;
|
|
|
import io.searchbox.core.Update;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@ -40,6 +41,7 @@ public class ElastricSearchSave {
|
|
|
|
|
|
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);
|
|
|
}
|
|
@ -53,4 +55,25 @@ public class ElastricSearchSave {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
public Boolean update(List<SaveModel> sms) {
|
|
|
try {
|
|
|
//得到链接
|
|
|
JestClient jestClient = elasticFactory.getJestClient();
|
|
|
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
for (SaveModel obj : sms) {
|
|
|
obj.setCreateTime(new Date());
|
|
|
Update index = new Update.Builder(obj).build();
|
|
|
bulk.addAction(index);
|
|
|
}
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
logger.info("update data count:" + sms.size());
|
|
|
logger.info("update flag:" + br.isSucceeded());
|
|
|
return br.isSucceeded();
|
|
|
} catch (Exception e) {
|
|
|
logger.error(" update error :" + e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
}
|