一、问题发现
有段代码更新 ES中的数据状态,将未读置成已读。是查一批,更新一批,再查再更新。
public Boolean updateDealStatus(WarningQuery warningQuery) {
....省略不重要的代码
while (true) {
// 调用服务
// ES查询不分页一次就出来10条
List list = warningEsDao.findByQuery(WarningZsdRiskEsEntity.class, warningZsdRiskQuery, esSort);
// 为空或者null就不继续跑了
if (list == null || list.isEmpty()) {
break;
}
log.info("查询出来的数量" + list.getSize());
// 将一批数据都置成已读
for (WarningZsdRiskEsEntity esEntity : list) {
esEntity.setDealStatus(1);
esEntity.setModified(System.currentTimeMillis());
warningEsDao.save(esEntity);
}
}
return true;
}
在测试的时候发现有问题。
我提前看了ES里这个范围的数据就27条,结果打印查询数量的日志log.info("查询出来的数量" + list.getSize());的结果类似这样。
查询出来的数量 10