商品索引需要手动删除的问题处理

This commit is contained in:
Chopper 2021-06-09 17:11:21 +08:00
parent f7201342d9
commit 590a039f10

View File

@ -153,10 +153,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
//索引名称拼接 //索引名称拼接
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME; String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
//如果索引不存在则创建索引 //索引初始化因为mapping结构问题
if (!indexExist(indexName)) { //但是如果索引已经自动生成过这里就不会创建索引设置mapping所以这里决定在初始化索引的同时将已有索引删除重新创建
createIndexRequest(indexName);
//如果索引存在则删除重新生成 这里应该有更优解
if (this.indexExist(indexName)) {
deleteIndexRequest(indexName);
} }
//如果索引不存在则创建索引
createIndexRequest(indexName);
if (goodsIndexList != null && !goodsIndexList.isEmpty()) { if (goodsIndexList != null && !goodsIndexList.isEmpty()) {
goodsIndexRepository.deleteAll(); goodsIndexRepository.deleteAll();
for (EsGoodsIndex goodsIndex : goodsIndexList) { for (EsGoodsIndex goodsIndex : goodsIndexList) {