ES异步同步数据

(cherry picked from commit e3cd4adf70)
This commit is contained in:
梁琦涛
2023-11-28 15:34:42 +08:00
committed by mzaxd
parent f9fcf4f9ee
commit 2f472479ab
2 changed files with 32 additions and 34 deletions
@@ -178,16 +178,11 @@ public class HomeSearchCheckEsPlanJob implements Job {
endIndex = startIndex + batchCount;
}
List<String> ids = listIds.subList(startIndex, endIndex);
// 异步生成记录
ForkJoinPool pool = new ForkJoinPool();
// 异步调用
CompletableFuture.runAsync(() -> {
try {
lawsHomeSearchService.updateEsData(lawsNewsFeed, String.join(",", ids), LawsHomeSearchCommon.LAWS_ES_ADD);
} catch (Exception e) {
log.error("ES同步异常:", e.getMessage());
}
}, pool);
try {
lawsHomeSearchService.updateEsData(lawsNewsFeed, String.join(",", ids), LawsHomeSearchCommon.LAWS_ES_ADD);
} catch (Exception e) {
log.error("ES同步异常:", e.getMessage());
}
startIndex = startIndex + batchCount; // 下一批
}
}
@@ -846,31 +846,34 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
throw new JeroBootException(ResultCommon.PARAMETER_NOT_RECOGNIZED);
}
log.info("================ES更新数据开始=================");
try{
//判断索引是否存在
boolean flagTemp;
flagTemp = jeroElasticsearchTemplate.indexExists(HomeSearchEnum.INDEX_NAME_DOCUMENT_ZQ.getValue());
if (!flagTemp) {
jeroElasticsearchTemplate.createIndex(HomeSearchEnum.INDEX_NAME_DOCUMENT_ZQ.getValue());
ForkJoinPool pool = new ForkJoinPool();
CompletableFuture.runAsync(()->{
try{
//判断索引是否存在
boolean flagTemp;
flagTemp = jeroElasticsearchTemplate.indexExists(HomeSearchEnum.INDEX_NAME_DOCUMENT_ZQ.getValue());
if (!flagTemp) {
jeroElasticsearchTemplate.createIndex(HomeSearchEnum.INDEX_NAME_DOCUMENT_ZQ.getValue());
}
switch (resourceType){
case LawsHomeSearchCommon.LAWS_DOMESTIC_STANDARD:
updateLawsDomesticStandardToEs(resourceType,ids,opType);
break;
case LawsHomeSearchCommon.LAWS_OVERSEAS_STANDARD:
updateLawsOverseasStandardToEs(resourceType,ids,opType);
break;
case LawsHomeSearchCommon.LAWS_ENTERPRISE_STANDARD:
updateLawsEnterpriseStandardToEs(resourceType,ids,opType);
break;
case LawsHomeSearchCommon.LAWS_NEWS_FEED:
updateLawsNewsFeedToEs(resourceType,ids,opType);
break;
default:break;
}
}catch (Exception e){
log.error("ES同步异常",e.getMessage());
}
switch (resourceType){
case LawsHomeSearchCommon.LAWS_DOMESTIC_STANDARD:
updateLawsDomesticStandardToEs(resourceType,ids,opType);
break;
case LawsHomeSearchCommon.LAWS_OVERSEAS_STANDARD:
updateLawsOverseasStandardToEs(resourceType,ids,opType);
break;
case LawsHomeSearchCommon.LAWS_ENTERPRISE_STANDARD:
updateLawsEnterpriseStandardToEs(resourceType,ids,opType);
break;
case LawsHomeSearchCommon.LAWS_NEWS_FEED:
updateLawsNewsFeedToEs(resourceType,ids,opType);
break;
default:break;
}
}catch (Exception e){
log.error("ES同步异常",e.getMessage());
}
},pool);
log.info("================ES更新数据结束=================");
}