Search in sources :

Example 1 with CommonException

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);
}
Also used : IndexQueryBuilder(org.springframework.data.elasticsearch.core.query.IndexQueryBuilder) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) ArrayList(java.util.ArrayList) CommonException(com.huaxing.springboot_elasticsearch.common.utils.CommonException)

Aggregations

CommonException (com.huaxing.springboot_elasticsearch.common.utils.CommonException)1 ArrayList (java.util.ArrayList)1 IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)1 IndexQueryBuilder (org.springframework.data.elasticsearch.core.query.IndexQueryBuilder)1