mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
fix:无法多次createIndex
This commit is contained in:
parent
a1816337cc
commit
05981f7996
@ -260,6 +260,10 @@ public interface BaseEsConstants {
|
||||
String NORMALIZER = "normalizer";
|
||||
String LOWERCASE_NORMALIZER = "lowercase_normalizer";
|
||||
|
||||
/**
|
||||
* 忽略index.analysis.normalizer.lowercase_normalizer.filter
|
||||
*/
|
||||
String LOWERCASE = "lowercase";
|
||||
/**
|
||||
* 默认缩放因子
|
||||
*/
|
||||
|
||||
@ -37,7 +37,7 @@ public class CreateIndexParam {
|
||||
/**
|
||||
* 用户通过自定义注解指定的settings信息
|
||||
*/
|
||||
private IndexSettings.Builder indexSettings;
|
||||
private IndexSettings indexSettings;
|
||||
/**
|
||||
* 用户手动指定的settings信息,优先级最高
|
||||
*/
|
||||
|
||||
@ -190,7 +190,7 @@ public class EntityInfo {
|
||||
/**
|
||||
* 通过自定义注解指定的索引settings
|
||||
*/
|
||||
private final IndexSettings.Builder indexSettings = new IndexSettings.Builder();
|
||||
private IndexSettings indexSettings;
|
||||
/**
|
||||
* 请求配置 默认值为官方内置的默认配置
|
||||
*/
|
||||
|
||||
@ -84,10 +84,10 @@ public class EntityInfoHelper {
|
||||
entityInfo = new EntityInfo();
|
||||
// 初始化表名(索引名)相关
|
||||
initIndexName(clazz, globalConfig, entityInfo);
|
||||
// 初始化索引settings相关
|
||||
initSettings(clazz, entityInfo);
|
||||
// 初始化字段相关
|
||||
initIndexFields(clazz, globalConfig, entityInfo);
|
||||
// 初始化索引settings相关
|
||||
initSettings(clazz, entityInfo);
|
||||
// 初始化封装@Join父子类型注解信息
|
||||
initJoin(clazz, globalConfig, entityInfo);
|
||||
|
||||
@ -787,8 +787,8 @@ public class EntityInfoHelper {
|
||||
entityInfo.setReplicasNum(settings.replicasNum());
|
||||
entityInfo.setShardsNum(settings.shardsNum());
|
||||
|
||||
IndexSettings.Builder builder = entityInfo.getIndexSettings()
|
||||
.numberOfReplicas(settings.replicasNum() + "")
|
||||
IndexSettings.Builder builder = new IndexSettings.Builder();
|
||||
builder.numberOfReplicas(settings.replicasNum() + "")
|
||||
.numberOfShards(settings.shardsNum() + "")
|
||||
.maxResultWindow(settings.maxResultWindow());
|
||||
|
||||
@ -798,6 +798,14 @@ public class EntityInfoHelper {
|
||||
|
||||
ISettingsProvider provider = settings.settingsProvider().getDeclaredConstructor().newInstance();
|
||||
provider.settings(builder);
|
||||
if (CollectionUtils.isNotEmpty(entityInfo.getFieldList())) {
|
||||
// 只要有其中一个字段加了忽略大小写,则在索引中创建此自定义配置,否则无需创建,不浪费资源
|
||||
if (entityInfo.getFieldList().stream().anyMatch(EntityFieldInfo::isIgnoreCase)) {
|
||||
builder.analysis(b -> b.normalizer(LOWERCASE_NORMALIZER,
|
||||
c -> c.custom(d -> d.filter(LOWERCASE))));
|
||||
}
|
||||
}
|
||||
entityInfo.setIndexSettings(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -59,10 +59,7 @@ public class IndexUtils {
|
||||
* index.analysis.normalizer.lowercase_normalizer.type值
|
||||
*/
|
||||
private static final String CUSTOM;
|
||||
/**
|
||||
* 忽略index.analysis.normalizer.lowercase_normalizer.filter
|
||||
*/
|
||||
private static final String LOWERCASE;
|
||||
|
||||
/**
|
||||
* dims索引字段名
|
||||
*/
|
||||
@ -82,7 +79,6 @@ public class IndexUtils {
|
||||
DEFAULT_IGNORE_ABOVE = 256;
|
||||
IGNORE_ABOVE_KEY = "ignore_above";
|
||||
CUSTOM = "custom";
|
||||
LOWERCASE = "lowercase";
|
||||
DIMS_KEY = "dims";
|
||||
EAGER_GLOBAL_ORDINALS = "eager_global_ordinals";
|
||||
COPY_TO_KEY = "copy_to";
|
||||
@ -121,15 +117,7 @@ public class IndexUtils {
|
||||
|
||||
// 用户未指定的settings信息
|
||||
if (Objects.isNull(indexParam.getSettings())) {
|
||||
IndexSettings.Builder settings = indexParam.getIndexSettings();
|
||||
// 只要有其中一个字段加了忽略大小写,则在索引中创建此自定义配置,否则无需创建,不浪费资源
|
||||
boolean ignoreCase = indexParam.getEsIndexParamList() != null && indexParam.getEsIndexParamList().stream()
|
||||
.anyMatch(EsIndexParam::isIgnoreCase);
|
||||
if (ignoreCase) {
|
||||
// 忽略大小写配置
|
||||
settings.analysis(b -> b.normalizer(LOWERCASE_NORMALIZER, c -> c.custom(d -> d.filter(LOWERCASE))));
|
||||
}
|
||||
x.settings(settings.build());
|
||||
x.settings(indexParam.getIndexSettings());
|
||||
} else {
|
||||
// 用户自定义settings
|
||||
x.settings(indexParam.getSettings().build());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user