mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 09:09:13 +08:00
feat:支持对单个索引指定数据刷新策略
This commit is contained in:
parent
6d8e6daa8d
commit
b7f46c30bf
@ -18,4 +18,10 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -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,11 @@ public @interface IndexName {
|
||||
* @return CRUD作用的路由
|
||||
*/
|
||||
String routing() default "";
|
||||
|
||||
/**
|
||||
* 数据刷新策略
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
@ -11,7 +11,11 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum RefreshPolicy {
|
||||
/**
|
||||
* 默认不刷新
|
||||
* 使用全局设置: easy-es.global-config.db-config.refresh-policy
|
||||
*/
|
||||
GLOBAL(""),
|
||||
/**
|
||||
* 不立即刷新 (es默认的数据刷新策略)
|
||||
*/
|
||||
NONE("false"),
|
||||
/**
|
||||
@ -2,6 +2,7 @@ package org.dromara.easyes.core.biz;
|
||||
|
||||
import org.dromara.easyes.annotation.rely.IdType;
|
||||
import org.dromara.easyes.annotation.rely.JoinField;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||
import com.alibaba.fastjson.PropertyNamingStrategy;
|
||||
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||
@ -177,6 +178,10 @@ 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.*;
|
||||
import org.dromara.easyes.core.biz.EntityFieldInfo;
|
||||
import org.dromara.easyes.core.biz.EntityInfo;
|
||||
@ -658,6 +659,11 @@ 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;
|
||||
|
||||
@ -15,7 +15,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等.
|
||||
@ -129,7 +131,7 @@ public class Document {
|
||||
*/
|
||||
@MultiIndexField(mainIndexField = @IndexField(fieldType = FieldType.KEYWORD),
|
||||
otherIndexFields = {@InnerIndexField(suffix = "zh", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART),
|
||||
@InnerIndexField(suffix = "pinyin", fieldType = FieldType.TEXT, analyzer = "pinyin")})
|
||||
@InnerIndexField(suffix = "pinyin", fieldType = FieldType.TEXT, analyzer = Analyzer.PINYIN)})
|
||||
private String multiField;
|
||||
/**
|
||||
* 英文名
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user