From 590a039f10d6bb2b0d83bc95b4f1a3ae2caf7bc9 Mon Sep 17 00:00:00 2001 From: Chopper Date: Wed, 9 Jun 2021 17:11:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E7=B4=A2=E5=BC=95=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=8B=E5=8A=A8=E5=88=A0=E9=99=A4=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/serviceimpl/EsGoodsIndexServiceImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index 26c3b1ba..d0df2bf7 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -153,10 +153,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements //索引名称拼接 String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME; - //如果索引不存在,则创建索引 - if (!indexExist(indexName)) { - createIndexRequest(indexName); + //索引初始化,因为mapping结构问题: + //但是如果索引已经自动生成过,这里就不会创建索引,设置mapping,所以这里决定在初始化索引的同时,将已有索引删除,重新创建 + + //如果索引存在,则删除,重新生成。 这里应该有更优解。 + if (this.indexExist(indexName)) { + deleteIndexRequest(indexName); } + + //如果索引不存在,则创建索引 + createIndexRequest(indexName); if (goodsIndexList != null && !goodsIndexList.isEmpty()) { goodsIndexRepository.deleteAll(); for (EsGoodsIndex goodsIndex : goodsIndexList) {