修复生成索引时no such index问题

This commit is contained in:
paulGao 2022-06-17 11:20:22 +08:00
parent 2e4c6f4284
commit d704e2eb55
5 changed files with 14 additions and 15 deletions

View File

@ -85,7 +85,6 @@ public abstract class BaseElasticsearchService {
*/ */
protected void createIndexRequest(String index) { protected void createIndexRequest(String index) {
try { try {
deleteIndexRequest(index);
CreateIndexRequest request = new CreateIndexRequest(index); CreateIndexRequest request = new CreateIndexRequest(index);
//Settings for this index //Settings for this index
request.settings(Settings.builder() request.settings(Settings.builder()

View File

@ -143,7 +143,8 @@ public interface GoodsSkuService extends IService<GoodsSku> {
/** /**
* 分页查询商品sku信息 * 分页查询商品sku信息
* *
* @param searchParams 查询参数 * @param page 分页参数
* @param queryWrapper 查询参数
* @return 商品sku信息 * @return 商品sku信息
*/ */
IPage<GoodsSkuDTO> getGoodsSkuDTOByPage(Page<GoodsSkuDTO> page, Wrapper<GoodsSkuDTO> queryWrapper); IPage<GoodsSkuDTO> getGoodsSkuDTOByPage(Page<GoodsSkuDTO> page, Wrapper<GoodsSkuDTO> queryWrapper);

View File

@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -85,15 +84,13 @@ public class FootprintServiceImpl extends ServiceImpl<FootprintMapper, FootPrint
//定义结果 //定义结果
IPage<EsGoodsIndex> esGoodsIndexIPage = new Page<EsGoodsIndex>(); IPage<EsGoodsIndex> esGoodsIndexIPage = new Page<>();
if (footPrintPages.getRecords() == null || footPrintPages.getRecords().isEmpty()) { if (footPrintPages.getRecords() == null || footPrintPages.getRecords().isEmpty()) {
return esGoodsIndexIPage; return esGoodsIndexIPage;
} else { } else {
List<EsGoodsIndex> list = esGoodsSearchService.getEsGoodsBySkuIds( List<EsGoodsIndex> list = esGoodsSearchService.getEsGoodsBySkuIds(
footPrintPages.getRecords().stream().map(item -> { footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()));
return item.getSkuId();
}).collect(Collectors.toList()));
//去除为空的商品数据 //去除为空的商品数据
list.removeIf(Objects::isNull); list.removeIf(Objects::isNull);

View File

@ -1,5 +1,6 @@
package cn.lili.modules.payment.kit.params.dto; package cn.lili.modules.payment.kit.params.dto;
import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.utils.StringUtils; import cn.lili.common.utils.StringUtils;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -18,7 +19,7 @@ import java.util.List;
@ToString @ToString
public class CashierParam { public class CashierParam {
static Long MAX_DETAIL_LENGTH = 30L; static final Long MAX_DETAIL_LENGTH = 30L;
@ApiModelProperty(value = "价格") @ApiModelProperty(value = "价格")
private Double price; private Double price;
@ -46,7 +47,7 @@ public class CashierParam {
private Double walletValue; private Double walletValue;
public String getDetail() { public String getDetail() {
if (StringUtils.isEmpty(detail)) { if (CharSequenceUtil.isEmpty(detail)) {
return "清单详细"; return "清单详细";
} }
return StringUtils.filterSpecialChart(StringUtils.sub(detail, 30)); return StringUtils.filterSpecialChart(StringUtils.sub(detail, 30));

View File

@ -86,9 +86,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
private final Map<String, Field> fieldMap = ReflectUtil.getFieldMap(EsGoodsIndex.class); private final Map<String, Field> fieldMap = ReflectUtil.getFieldMap(EsGoodsIndex.class);
private final String KEY_SUCCESS = "success"; private static final String KEY_SUCCESS = "success";
private final String KEY_FAIL = "fail"; private static final String KEY_FAIL = "fail";
private final String KEY_PROCESSED = "processed"; private static final String KEY_PROCESSED = "processed";
@Autowired @Autowired
private ElasticsearchProperties elasticsearchProperties; private ElasticsearchProperties elasticsearchProperties;
@ -105,8 +105,6 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
@Autowired @Autowired
private GoodsSkuService goodsSkuService; private GoodsSkuService goodsSkuService;
@Autowired @Autowired
private GoodsService goodsService;
@Autowired
private BrandService brandService; private BrandService brandService;
@Autowired @Autowired
@ -425,8 +423,11 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
//如果索引存在则删除重新生成 这里应该有更优解 //如果索引存在则删除重新生成 这里应该有更优解
boolean indexExist = this.indexExist(indexName); boolean indexExist = this.indexExist(indexName);
if (regeneratorIndex || !indexExist) { if (regeneratorIndex || !indexExist) {
if (indexExist) {
this.deleteIndexRequest(indexName);
}
//如果索引不存在则创建索引 //如果索引不存在则创建索引
createIndexRequest(indexName); this.createIndexRequest(indexName);
} }
Map<String, Long> resultMap = (Map<String, Long>) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); Map<String, Long> resultMap = (Map<String, Long>) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix());