mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-07 09:39:04 +08:00
feat:支持对单个索引指定数据刷新策略
This commit is contained in:
parent
6d8e6daa8d
commit
b7f46c30bf
@ -18,4 +18,10 @@
|
|||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.easyes.annotation;
|
package org.dromara.easyes.annotation;
|
||||||
|
|
||||||
import org.dromara.easyes.annotation.rely.DefaultChildClass;
|
import org.dromara.easyes.annotation.rely.DefaultChildClass;
|
||||||
|
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -81,4 +82,11 @@ public @interface IndexName {
|
|||||||
* @return CRUD作用的路由
|
* @return CRUD作用的路由
|
||||||
*/
|
*/
|
||||||
String routing() default "";
|
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.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -11,7 +11,11 @@ import lombok.Getter;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum RefreshPolicy {
|
public enum RefreshPolicy {
|
||||||
/**
|
/**
|
||||||
* 默认不刷新
|
* 使用全局设置: easy-es.global-config.db-config.refresh-policy
|
||||||
|
*/
|
||||||
|
GLOBAL(""),
|
||||||
|
/**
|
||||||
|
* 不立即刷新 (es默认的数据刷新策略)
|
||||||
*/
|
*/
|
||||||
NONE("false"),
|
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.IdType;
|
||||||
import org.dromara.easyes.annotation.rely.JoinField;
|
import org.dromara.easyes.annotation.rely.JoinField;
|
||||||
|
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||||
import com.alibaba.fastjson.PropertyNamingStrategy;
|
import com.alibaba.fastjson.PropertyNamingStrategy;
|
||||||
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||||
@ -177,6 +178,10 @@ public class EntityInfo {
|
|||||||
*/
|
*/
|
||||||
private final Map<Class<?>, List<SerializeFilter>> classSimplePropertyPreFilterMap = new HashMap<>();
|
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.FieldStrategy;
|
||||||
import org.dromara.easyes.annotation.rely.IdType;
|
import org.dromara.easyes.annotation.rely.IdType;
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
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 org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||||
|
|
||||||
import static org.dromara.easyes.common.constants.BaseEsConstants.EMPTY_STR;
|
import static org.dromara.easyes.common.constants.BaseEsConstants.EMPTY_STR;
|
||||||
@ -79,7 +79,7 @@ public class GlobalConfig {
|
|||||||
*/
|
*/
|
||||||
private boolean enableTrackTotalHits = true;
|
private boolean enableTrackTotalHits = true;
|
||||||
/**
|
/**
|
||||||
* data refresh policy 数据刷新策略,默认为NONE
|
* data refresh policy 数据刷新策略,es默认的数据刷新策略为NONE
|
||||||
*/
|
*/
|
||||||
private RefreshPolicy refreshPolicy = RefreshPolicy.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.constants.BaseEsConstants;
|
||||||
import org.dromara.easyes.common.enums.EsQueryTypeEnum;
|
import org.dromara.easyes.common.enums.EsQueryTypeEnum;
|
||||||
import org.dromara.easyes.common.enums.MethodEnum;
|
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.common.utils.*;
|
||||||
import org.dromara.easyes.core.biz.*;
|
import org.dromara.easyes.core.biz.*;
|
||||||
import org.dromara.easyes.core.cache.BaseCache;
|
import org.dromara.easyes.core.cache.BaseCache;
|
||||||
@ -1495,7 +1495,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
* @return 刷新策略
|
* @return 刷新策略
|
||||||
*/
|
*/
|
||||||
private String getRefreshPolicy() {
|
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.DefaultNestedClass;
|
||||||
import org.dromara.easyes.annotation.rely.FieldType;
|
import org.dromara.easyes.annotation.rely.FieldType;
|
||||||
import org.dromara.easyes.annotation.rely.IdType;
|
import org.dromara.easyes.annotation.rely.IdType;
|
||||||
|
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||||
import org.dromara.easyes.common.utils.*;
|
import org.dromara.easyes.common.utils.*;
|
||||||
import org.dromara.easyes.core.biz.EntityFieldInfo;
|
import org.dromara.easyes.core.biz.EntityFieldInfo;
|
||||||
import org.dromara.easyes.core.biz.EntityInfo;
|
import org.dromara.easyes.core.biz.EntityInfo;
|
||||||
@ -658,6 +659,11 @@ public class EntityInfoHelper {
|
|||||||
entityInfo.setReplicasNum(table.replicasNum());
|
entityInfo.setReplicasNum(table.replicasNum());
|
||||||
entityInfo.setChild(table.child());
|
entityInfo.setChild(table.child());
|
||||||
entityInfo.setChildClass(table.childClass());
|
entityInfo.setChildClass(table.childClass());
|
||||||
|
RefreshPolicy refreshPolicy = table.refreshPolicy();
|
||||||
|
if (RefreshPolicy.GLOBAL.equals(refreshPolicy)) {
|
||||||
|
refreshPolicy = dbConfig.getRefreshPolicy();
|
||||||
|
}
|
||||||
|
entityInfo.setRefreshPolicy(refreshPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetIndexName = indexName;
|
String targetIndexName = indexName;
|
||||||
|
|||||||
@ -15,7 +15,9 @@ import java.util.List;
|
|||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@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 {
|
public class Document {
|
||||||
/**
|
/**
|
||||||
* es中的唯一id,字段名随便起,我这里演示用esId,你也可以用id(推荐),bizId等.
|
* es中的唯一id,字段名随便起,我这里演示用esId,你也可以用id(推荐),bizId等.
|
||||||
@ -129,7 +131,7 @@ public class Document {
|
|||||||
*/
|
*/
|
||||||
@MultiIndexField(mainIndexField = @IndexField(fieldType = FieldType.KEYWORD),
|
@MultiIndexField(mainIndexField = @IndexField(fieldType = FieldType.KEYWORD),
|
||||||
otherIndexFields = {@InnerIndexField(suffix = "zh", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART),
|
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;
|
private String multiField;
|
||||||
/**
|
/**
|
||||||
* 英文名
|
* 英文名
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user