use of com.huaxing.springboot_elasticsearch.common.utils.CommonException in project HuaXing-learningCenter by 17666555910.
the class BaseServiceImpl method batchInsertOrUpdate.
@Override
public void batchInsertOrUpdate(List<T> entityModelList) {
if (CollectionUtils.isEmpty(entityModelList)) {
throw new CommonException("entityModelList Can't be empty");
}
// 判断索引是否存在 若不存在则创建索引和映射
if (!elasticsearchTemplate.indexExists(getEntityClass())) {
this.createEntityEsIndex();
}
List<IndexQuery> queries = new ArrayList<>();
for (T entityEsModel : entityModelList) {
IndexQuery indexQuery = new IndexQueryBuilder().withId(entityEsModel.getId()).withObject(entityEsModel).build();
queries.add(indexQuery);
}
// 批量插入
this.bulkInsert(queries);
}
Aggregations