Search in sources :

Example 1 with EsEntity

use of com.github.lybgeek.common.elasticsearch.model.EsEntity in project springboot-learning by lyb-geek.

the class AbstractCustomElasticsearchRepository method save.

@Override
public boolean save(T entity) {
    String indexName = this.getIndexName();
    EsEntity esEntity = this.convertDoToEsEntity(entity);
    return elasticsearchHelper.saveOrUpdate(indexName, esEntity);
}
Also used : EsEntity(com.github.lybgeek.common.elasticsearch.model.EsEntity)

Example 2 with EsEntity

use of com.github.lybgeek.common.elasticsearch.model.EsEntity in project springboot-learning by lyb-geek.

the class ElasticsearchAspect method saveOrUpdate.

private void saveOrUpdate(JoinPoint jp, Object retVal, EsOperate operate) {
    String methodName = jp.getSignature().getName();
    Object id = elasticsearchHelper.getEsId(retVal);
    EsEntity esEntity = new EsEntity();
    esEntity.setData(retVal);
    if (ObjectUtils.isNotEmpty(id)) {
        esEntity.setId(id.toString());
    }
    boolean isOK = elasticsearchHelper.saveOrUpdate(operate.indexName(), esEntity);
    log.info("{} saveOrUpdateToEs success {}", methodName, isOK);
}
Also used : EsEntity(com.github.lybgeek.common.elasticsearch.model.EsEntity)

Example 3 with EsEntity

use of com.github.lybgeek.common.elasticsearch.model.EsEntity in project springboot-learning by lyb-geek.

the class AbstractCustomElasticsearchRepository method convertDoToEsEntity.

private final EsEntity<T> convertDoToEsEntity(T entity) {
    EsEntity esEntity = new EsEntity();
    Object id = elasticsearchHelper.getEsId(entity);
    if (ObjectUtils.isNotEmpty(id)) {
        esEntity.setId(id.toString());
    }
    esEntity.setData(entity);
    return esEntity;
}
Also used : EsEntity(com.github.lybgeek.common.elasticsearch.model.EsEntity)

Example 4 with EsEntity

use of com.github.lybgeek.common.elasticsearch.model.EsEntity in project springboot-learning by lyb-geek.

the class CustomShortUrlEsServiceImpl method save.

@Override
public String save(ShortUrlDTO shortUrlDTO) {
    EsEntity esEntity = EsEntity.builder().id(shortUrlDTO.getId().toString()).data(shortUrlDTO).build();
    boolean isOk = elasticsearchHelper.saveOrUpdate(ElasticsearchConstant.SHORT_URL_INDEX, esEntity);
    if (isOk) {
        return esEntity.getId();
    }
    return null;
}
Also used : EsEntity(com.github.lybgeek.common.elasticsearch.model.EsEntity)

Example 5 with EsEntity

use of com.github.lybgeek.common.elasticsearch.model.EsEntity in project springboot-learning by lyb-geek.

the class ElasticsearchEvent method syncShortUrlToEs.

@Async
@EventListener
public void syncShortUrlToEs(ShortUrl shortUrl) {
    ShortUrlDTO shortUrlDO = new ShortUrlDTO();
    BeanUtils.copyProperties(shortUrl, shortUrlDO);
    log.info("syncShortUrlToEs -> {}", shortUrlDO);
    EsEntity esEntity = EsEntity.builder().id(shortUrlDO.getId().toString()).data(shortUrlDO).build();
    elasticsearchHelper.saveOrUpdate(ElasticsearchConstant.SHORT_URL_INDEX, esEntity);
}
Also used : EsEntity(com.github.lybgeek.common.elasticsearch.model.EsEntity) ShortUrlDTO(com.github.lybgeek.shorturl.dto.ShortUrlDTO) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

EsEntity (com.github.lybgeek.common.elasticsearch.model.EsEntity)5 ShortUrlDTO (com.github.lybgeek.shorturl.dto.ShortUrlDTO)1 EventListener (org.springframework.context.event.EventListener)1 Async (org.springframework.scheduling.annotation.Async)1