!150 优化生成索引mapping日志
Merge pull request !150 from OceansDeep/feature/pg
This commit is contained in:
@@ -29,7 +29,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* @author paulG
|
||||
@@ -343,20 +342,20 @@ public abstract class BaseElasticsearchService {
|
||||
PutMappingRequest request = new PutMappingRequest(index)
|
||||
.source(source, XContentType.JSON);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<AcknowledgedResponse> response = new AtomicReference<>();
|
||||
client.indices().putMappingAsync(
|
||||
request,
|
||||
RequestOptions.DEFAULT,
|
||||
new ActionListener<AcknowledgedResponse>() {
|
||||
@Override
|
||||
public void onResponse(AcknowledgedResponse r) {
|
||||
response.set(r);
|
||||
latch.countDown();
|
||||
log.info("创建索引mapping成功:{}", r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
latch.countDown();
|
||||
log.error("创建索引mapping失败", e);
|
||||
}
|
||||
});
|
||||
latch.await(10, TimeUnit.SECONDS);
|
||||
|
||||
@@ -38,6 +38,13 @@ public interface EsGoodsIndexService {
|
||||
*/
|
||||
void addIndex(EsGoodsIndex goods);
|
||||
|
||||
/**
|
||||
* 添加商品索引
|
||||
*
|
||||
* @param goods 商品索引信息
|
||||
*/
|
||||
void addIndex(List<EsGoodsIndex> goods);
|
||||
|
||||
/**
|
||||
* 更新商品索引
|
||||
*
|
||||
|
||||
@@ -210,6 +210,20 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品索引
|
||||
*
|
||||
* @param goods 商品索引信息
|
||||
*/
|
||||
@Override
|
||||
public void addIndex(List<EsGoodsIndex> goods) {
|
||||
try {
|
||||
goodsIndexRepository.saveAll(goods);
|
||||
} catch (Exception e) {
|
||||
log.error("批量为商品生成索引异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIndex(EsGoodsIndex goods) {
|
||||
goodsIndexRepository.save(goods);
|
||||
|
||||
Reference in New Issue
Block a user