mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
feat:支持对单个索引指定数据刷新策略
This commit is contained in:
parent
4a402ed009
commit
0f863a37dd
@ -1,6 +1,7 @@
|
||||
package org.dromara.easyes.annotation;
|
||||
|
||||
import org.dromara.easyes.annotation.rely.DefaultChildClass;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -81,4 +82,6 @@ public @interface IndexName {
|
||||
* @return CRUD作用的路由
|
||||
*/
|
||||
String routing() default "";
|
||||
|
||||
RefreshPolicy refreshPolicy() default RefreshPolicy.GLOBAL;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package org.dromara.easyes.common.enums;
|
||||
package org.dromara.easyes.annotation.rely;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@ -7,11 +7,17 @@ import lombok.Getter;
|
||||
* 数据刷新策略枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
*
|
||||
* @see org.elasticsearch.action.support.WriteRequest.RefreshPolicy
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum RefreshPolicy {
|
||||
/**
|
||||
* 默认不刷新
|
||||
* 使用全局设置: easy-es.global-config.db-config.refresh-policy
|
||||
*/
|
||||
GLOBAL(""),
|
||||
/**
|
||||
* 不立即刷新 (es默认的数据刷新策略)
|
||||
*/
|
||||
NONE("false"),
|
||||
/**
|
||||
@ -8,6 +8,7 @@ import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
@ -177,6 +178,8 @@ public class EntityInfo {
|
||||
*/
|
||||
private final Map<Class<?>, List<SerializeFilter>> classSimplePropertyPreFilterMap = new HashMap<>();
|
||||
|
||||
private RefreshPolicy refreshPolicy;
|
||||
|
||||
/**
|
||||
* 获取需要进行查询的字段列表
|
||||
*
|
||||
|
||||
@ -5,7 +5,7 @@ import lombok.Data;
|
||||
import org.dromara.easyes.annotation.rely.FieldStrategy;
|
||||
import org.dromara.easyes.annotation.rely.IdType;
|
||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import org.dromara.easyes.common.enums.RefreshPolicy;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
import static org.dromara.easyes.common.constants.BaseEsConstants.EMPTY_STR;
|
||||
@ -79,7 +79,7 @@ public class GlobalConfig {
|
||||
*/
|
||||
private boolean enableTrackTotalHits = true;
|
||||
/**
|
||||
* data refresh policy 数据刷新策略,默认为NONE
|
||||
* data refresh policy 数据刷新策略,es默认的数据刷新策略为NONE
|
||||
*/
|
||||
private RefreshPolicy refreshPolicy = RefreshPolicy.NONE;
|
||||
/**
|
||||
|
||||
@ -13,7 +13,7 @@ import org.dromara.easyes.annotation.rely.IdType;
|
||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||
import org.dromara.easyes.common.enums.EsQueryTypeEnum;
|
||||
import org.dromara.easyes.common.enums.MethodEnum;
|
||||
import org.dromara.easyes.common.enums.RefreshPolicy;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
import org.dromara.easyes.common.utils.*;
|
||||
import org.dromara.easyes.core.biz.*;
|
||||
import org.dromara.easyes.core.cache.BaseCache;
|
||||
@ -1495,7 +1495,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
* @return 刷新策略
|
||||
*/
|
||||
private String getRefreshPolicy() {
|
||||
return GlobalConfigCache.getGlobalConfig().getDbConfig().getRefreshPolicy().getValue();
|
||||
return EntityInfoHelper.getEntityInfo(entityClass).getRefreshPolicy().getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -8,6 +8,7 @@ import org.dromara.easyes.annotation.*;
|
||||
import org.dromara.easyes.annotation.rely.DefaultNestedClass;
|
||||
import org.dromara.easyes.annotation.rely.FieldType;
|
||||
import org.dromara.easyes.annotation.rely.IdType;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
import org.dromara.easyes.common.utils.ClassUtils;
|
||||
import org.dromara.easyes.common.utils.FastJsonUtils;
|
||||
import org.dromara.easyes.common.utils.ReflectionKit;
|
||||
@ -616,6 +617,12 @@ public class EntityInfoHelper {
|
||||
entityInfo.setReplicasNum(table.replicasNum());
|
||||
entityInfo.setChild(table.child());
|
||||
entityInfo.setChildClass(table.childClass());
|
||||
|
||||
RefreshPolicy refreshPolicy = table.refreshPolicy();
|
||||
if (RefreshPolicy.GLOBAL.equals(refreshPolicy)) {
|
||||
refreshPolicy = dbConfig.getRefreshPolicy();
|
||||
}
|
||||
entityInfo.setRefreshPolicy(refreshPolicy);
|
||||
}
|
||||
|
||||
String targetIndexName = indexName;
|
||||
|
||||
@ -5,6 +5,7 @@ import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.easyes.annotation.*;
|
||||
import org.dromara.easyes.annotation.rely.*;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -15,7 +16,9 @@ import java.util.List;
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@IndexName(value = "easyes_document", shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true, childClass = Comment.class, routing = "testRouting")
|
||||
@IndexName(value = "easyes_document", shardsNum = 3, replicasNum = 2,
|
||||
keepGlobalPrefix = true, childClass = Comment.class, routing = "testRouting",
|
||||
refreshPolicy = RefreshPolicy.IMMEDIATE)
|
||||
public class Document {
|
||||
/**
|
||||
* es中的唯一id,字段名随便起,我这里演示用esId,你也可以用id(推荐),bizId等.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user