!98 优化更新索引促销方式,以更新部分字段的方式更新。不在以刷新索引的方式更新。

Merge pull request !98 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2021-12-29 11:48:56 +00:00 committed by Gitee
commit b6d01cb850
2 changed files with 12 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package cn.lili.listener;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ClassLoaderUtil; import cn.hutool.core.util.ClassLoaderUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
@ -141,7 +140,7 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
} }
break; break;
case UPDATE_GOODS_INDEX_PROMOTIONS: case UPDATE_GOODS_INDEX_PROMOTIONS:
ThreadUtil.execAsync(() -> this.updateGoodsIndexPromotions(new String(messageExt.getBody()))); this.updateGoodsIndexPromotions(new String(messageExt.getBody()));
break; break;
case DELETE_GOODS_INDEX_PROMOTIONS: case DELETE_GOODS_INDEX_PROMOTIONS:
BasePromotions promotions = JSONUtil.toBean(new String(messageExt.getBody()), BasePromotions.class); BasePromotions promotions = JSONUtil.toBean(new String(messageExt.getBody()), BasePromotions.class);

View File

@ -628,10 +628,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
String s = jsonObject.toString(); String s = jsonObject.toString();
String promotionsStr = s.replace("{", "[").replace("}", "]"); String promotionsStr = s.replace("{", "[").replace("}", "]");
UpdateByQueryRequest update = new UpdateByQueryRequest(getIndexName()); UpdateRequest updateRequest = new UpdateRequest();
update.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.termsQuery("id", id))); updateRequest.index(getIndexName());
update.setScript(new Script("ctx._source." + "promotionMap" + "=" + promotionsStr + ";")); updateRequest.id(id);
client.updateByQueryAsync(update, RequestOptions.DEFAULT, this.actionListener()); updateRequest.retryOnConflict(5);
updateRequest.script(new Script("ctx._source." + "promotionMap" + "=" + promotionsStr + ";"));
try {
client.update(updateRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
log.error("更新商品索引促销信息错误", e);
}
} }
/** /**