From 2feafdef309f6f1e0160e7226e013675ec27d325 Mon Sep 17 00:00:00 2001 From: jaime Date: Thu, 27 Feb 2025 15:42:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E7=94=A8=E6=88=B7id=E5=88=97?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8source=E4=B8=AD=E6=97=B6,=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=5Fid=E8=BF=9B=E8=A1=8C=E6=9F=A5=E8=AF=A2/?= =?UTF-8?q?=E6=8E=92=E5=BA=8F/=E8=81=9A=E5=90=88,=20=E6=AD=A4=E6=97=B6?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=BC=80=E5=90=AF=E9=9B=86=E7=BE=A4=E9=85=8D?= =?UTF-8?q?=E7=BD=AEindices.id=5Ffield=5Fdata.enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easyes/core/kernel/WrapperProcessor.java | 127 +++++++++--------- .../easyes/core/toolkit/FieldUtils.java | 43 ++++-- .../dromara/easyes/test/entity/Document.java | 2 + .../org/dromara/easyes/test/all/AllTest.java | 74 +++++----- .../easyes/test/all/XmlScannerAllTest.java | 2 +- .../org/dromara/easyes/test/all/AllTest.java | 2 +- 6 files changed, 136 insertions(+), 114 deletions(-) diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/WrapperProcessor.java b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/WrapperProcessor.java index 237b8d12..d18360a3 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/WrapperProcessor.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/WrapperProcessor.java @@ -97,31 +97,31 @@ public class WrapperProcessor { setBool(bool, param.getQueryBuilder().build(), param.getPrevQueryType()); break; case TERM: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.term(p -> p.field(realField).value(fieldValue(param.getVal())).boost(param.getBoost()))); setBool(bool, query, param.getPrevQueryType()); break; case MATCH: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.match(p -> p.field(realField).query(fieldValue(param.getVal())).boost(param.getBoost()))); setBool(bool, query, param.getPrevQueryType()); break; case MATCH_PHRASE: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.matchPhrase(p -> p.field(realField).query((String) param.getVal()).boost(param.getBoost()))); setBool(bool, query, param.getPrevQueryType()); break; case MATCH_PHRASE_PREFIX: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.matchPhrasePrefix(p -> p.field(realField).query((String) param.getVal()).boost(param.getBoost()).maxExpansions((int) param.getExt1()))); setBool(bool, query, param.getPrevQueryType()); break; case MULTI_MATCH: - List realFields = getRealFields(param.getColumns(), mappingColumnMap); + List realFields = getRealFields(param.getColumns(), mappingColumnMap, entityInfo); query = Query.of(q -> q.multiMatch(p -> p.query((String) param.getVal()).fields(realFields) .operator((Operator) param.getExt1()).minimumShouldMatch(param.getExt2() + PERCENT_SIGN))); setBool(bool, query, param.getPrevQueryType()); @@ -135,12 +135,12 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case PREFIX: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.prefix(p -> p.field(realField).value((String) param.getVal()).boost(param.getBoost()))); setBool(bool, query, param.getPrevQueryType()); break; case GT: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.range(p -> p.untyped(v -> { v.field(realField).gt(JsonData.of(param.getVal())).boost(param.getBoost()); @@ -152,7 +152,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case GE: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.range(p -> p.untyped(v -> { v.field(realField).gte(JsonData.of(param.getVal())).boost(param.getBoost()); @@ -164,7 +164,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case LT: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.range(p -> p.untyped(v -> { v.field(realField).lt(JsonData.of(param.getVal())).boost(param.getBoost()); @@ -176,7 +176,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case LE: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.range(p -> p.untyped(v -> { v.field(realField).lte(JsonData.of(param.getVal())).boost(param.getBoost()); @@ -188,7 +188,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case BETWEEN: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.range(p -> p.untyped(v -> { v.field(realField).gte(JsonData.of(param.getExt1())).lte(JsonData.of(param.getExt2())).boost(param.getBoost()); @@ -200,24 +200,24 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case WILDCARD: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); query = Query.of(q -> q.wildcard(p -> p.field(realField).value((String) param.getVal()).boost(param.getBoost()))); setBool(bool, query, param.getPrevQueryType()); break; case TERMS: - realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap); + realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo); List fieldValueList = ((Collection) param.getVal()).stream() .map(WrapperProcessor::fieldValue).collect(Collectors.toList()); query = Query.of(q -> q.terms(p -> p.field(realField).terms(t -> t.value(fieldValueList)))); setBool(bool, query, param.getPrevQueryType()); break; case EXISTS: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.exists(p -> p.field(realField).boost(param.getBoost()))); setBool(bool, query, param.getPrevQueryType()); break; case GEO_BOUNDING_BOX: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.geoBoundingBox(p -> p.field(realField) .boundingBox(x -> x.tlbr(y -> y .topLeft((GeoLocation) param.getExt1()) @@ -227,7 +227,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case GEO_DISTANCE: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.geoDistance(p -> { String unit = param.getExt1() == null ? DistanceUnit.Kilometers.jsonValue() : ((DistanceUnit) param.getExt1()).jsonValue(); Double distance = (Double) param.getVal(); @@ -242,19 +242,19 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case GEO_POLYGON: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.geoPolygon(p -> p.field(realField).polygon(x -> x.points((List) param.getVal())))); setBool(bool, query, param.getPrevQueryType()); break; case GEO_SHAPE_ID: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.geoShape(p -> p.field(realField).shape(x -> x.indexedShape(y -> y.id((String) param.getVal()))))); setBool(bool, query, param.getPrevQueryType()); break; case GEO_SHAPE: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = QueryBuilders.geoShape() .field(realField) .shape(x -> x @@ -267,7 +267,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case PARENT_ID: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(q -> q.parentId(p -> p.type(realField).id((String) param.getVal()))); setBool(bool, query, param.getPrevQueryType()); break; @@ -280,7 +280,7 @@ public class WrapperProcessor { setBool(bool, query, param.getPrevQueryType()); break; case NESTED: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); String[] split = param.getColumn().split(SIGN); String path = split[split.length - 1]; query = Query.of(b -> b.bool(x -> getBool(children, x, entityInfo, path))); @@ -293,7 +293,7 @@ public class WrapperProcessor { case HAS_PARENT: // 如果用户没指定type框架可根据entityInfo上下文自行推断出其父type String column = Optional.ofNullable(param.getColumn()).orElse(entityInfo.getParentJoinAlias()); - realField = getRealField(column, mappingColumnMap); + realField = getRealField(column, mappingColumnMap, entityInfo); query = Query.of(t -> t.bool(b -> getBool(children, b, entityInfo, param.getColumn()))); HasParentQuery.Builder hasParentQueryBuilder = new HasParentQuery.Builder() .ignoreUnmapped(false) @@ -303,7 +303,7 @@ public class WrapperProcessor { setBool(bool, Query.of(x -> x.hasParent(hasParentQueryBuilder.build())), param.getPrevQueryType()); break; case HAS_CHILD: - realField = getRealField(param.getColumn(), mappingColumnMap); + realField = getRealField(param.getColumn(), mappingColumnMap, entityInfo); query = Query.of(t -> t.bool(b -> getBool(children, b, entityInfo, param.getColumn()))); HasChildQuery.Builder hasChildQueryBuilder = new HasChildQuery.Builder() .minChildren(1) @@ -436,10 +436,10 @@ public class WrapperProcessor { setHighLight(entityInfo.getHighlightParams(), builder); // 设置用户指定的各种排序规则 - setSort(wrapper, mappingColumnMap, builder); + setSort(wrapper, mappingColumnMap, entityInfo, builder); // 设置查询或不查询字段 - setFetchSource(wrapper, mappingColumnMap, builder); + setFetchSource(wrapper, mappingColumnMap, entityInfo, builder); // 设置排除_score 小于 min_score 中指定的最小值的文档 Optional.ofNullable(wrapper.minScore).ifPresent(builder::minScore); @@ -448,7 +448,7 @@ public class WrapperProcessor { Optional.ofNullable(wrapper.trackScores).ifPresent(builder::trackScores); // 设置聚合参数 - setAggregations(wrapper, mappingColumnMap, builder); + setAggregations(wrapper, mappingColumnMap, entityInfo, builder); // 设置查询起止参数 Optional.ofNullable(wrapper.from).ifPresent(builder::from); @@ -535,36 +535,37 @@ public class WrapperProcessor { /** * 设置查询/不查询字段列表 * - * @param wrapper 参数包装类 - * @param mappingColumnMap 字段映射map - * @param searchSourceBuilder 查询参数建造者 + * @param wrapper 参数包装类 + * @param mappingColumnMap 字段映射map + * @param entityInfo 索引信息 + * @param searchBuilder 查询参数建造者 */ - private static void setFetchSource(Wrapper wrapper, Map mappingColumnMap, SearchRequest.Builder searchSourceBuilder) { + private static void setFetchSource(Wrapper wrapper, Map mappingColumnMap, EntityInfo entityInfo, SearchRequest.Builder searchBuilder) { if (ArrayUtils.isEmpty(wrapper.include) && ArrayUtils.isEmpty(wrapper.exclude)) { return; } // 获取实际字段 - List includes = FieldUtils.getRealFields(wrapper.include, mappingColumnMap); - List excludes = FieldUtils.getRealFields(wrapper.exclude, mappingColumnMap); - searchSourceBuilder.source(x -> x.filter(y -> y.includes(includes).excludes(excludes))); + List includes = FieldUtils.getRealFields(wrapper.include, mappingColumnMap, entityInfo); + List excludes = FieldUtils.getRealFields(wrapper.exclude, mappingColumnMap, entityInfo); + searchBuilder.source(x -> x.filter(y -> y.includes(includes).excludes(excludes))); } /** * 设置高亮参数 * - * @param highLightParams 高亮参数列表 - * @param searchSourceBuilder 查询参数建造者 + * @param highLightParams 高亮参数列表 + * @param searchBuilder 查询参数建造者 */ - private static void setHighLight(List highLightParams, SearchRequest.Builder searchSourceBuilder) { + private static void setHighLight(List highLightParams, SearchRequest.Builder searchBuilder) { if (CollectionUtils.isEmpty(highLightParams)) { return; } // 初始化高亮参数 Highlight.Builder highlightBuilder = initHighlightBuilder(highLightParams, null); - Optional.ofNullable(highlightBuilder).map(Highlight.Builder::build).ifPresent(searchSourceBuilder::highlight); + Optional.ofNullable(highlightBuilder).map(Highlight.Builder::build).ifPresent(searchBuilder::highlight); } private static Highlight.Builder initHighlightBuilder(List highLightParams, String path) { @@ -596,19 +597,20 @@ public class WrapperProcessor { /** * 设置排序参数 * - * @param wrapper 参数包装类 - * @param mappingColumnMap 字段映射map - * @param searchSourceBuilder 查询参数建造者 + * @param wrapper 参数包装类 + * @param mappingColumnMap 字段映射map + * @param entityInfo 索引信息 + * @param searchBuilder 查询参数建造者 */ - private static void setSort(Wrapper wrapper, Map mappingColumnMap, SearchRequest.Builder searchSourceBuilder) { + private static void setSort(Wrapper wrapper, Map mappingColumnMap, EntityInfo entityInfo, SearchRequest.Builder searchBuilder) { // 批量设置排序字段 if (CollectionUtils.isNotEmpty(wrapper.baseSortParams)) { wrapper.baseSortParams.forEach(baseSortParam -> { // 获取es中的实际字段 有可能已经被用户自定义或者驼峰转成下划线 String realField = Objects.isNull(baseSortParam.getSortField()) ? - null : getRealField(baseSortParam.getSortField(), mappingColumnMap); + null : getRealField(baseSortParam.getSortField(), mappingColumnMap, entityInfo); SortOptions sortBuilder = getSortBuilder(realField, baseSortParam); - Optional.ofNullable(sortBuilder).ifPresent(searchSourceBuilder::sort); + Optional.ofNullable(sortBuilder).ifPresent(searchBuilder::sort); }); } @@ -625,7 +627,7 @@ public class WrapperProcessor { if (SortOrder.Desc.toString().equalsIgnoreCase(orderByParam.getSort())) { fieldSortBuilder.order(SortOrder.Desc); } - searchSourceBuilder.sort(x -> x.field(fieldSortBuilder.build())); + searchBuilder.sort(x -> x.field(fieldSortBuilder.build())); }); } } @@ -639,24 +641,18 @@ public class WrapperProcessor { * @return 排序器 */ private static SortOptions getSortBuilder(String realField, BaseSortParam baseSortParam) { - switch (baseSortParam.getOrderTypeEnum()) { - case FIELD: - return SortOptions.of(x -> x.field(y -> y.field(realField).order(baseSortParam.getSortOrder()))); - case SCORE: - return SortOptions.of(x -> x.score(y -> y.order(baseSortParam.getSortOrder()))); - case GEO: - return SortOptions.of(x -> x.geoDistance(y -> y - .field(realField) - .location(baseSortParam.getGeoPoints()) - .order(baseSortParam.getSortOrder()) - .distanceType(baseSortParam.getGeoDistanceType()) - .unit(baseSortParam.getUnit()) - )); - case CUSTOMIZE: - return baseSortParam.getSortBuilder(); - default: - return null; - } + return switch (baseSortParam.getOrderTypeEnum()) { + case FIELD -> SortOptions.of(x -> x.field(y -> y.field(realField).order(baseSortParam.getSortOrder()))); + case SCORE -> SortOptions.of(x -> x.score(y -> y.order(baseSortParam.getSortOrder()))); + case GEO -> SortOptions.of(x -> x.geoDistance(y -> y + .field(realField) + .location(baseSortParam.getGeoPoints()) + .order(baseSortParam.getSortOrder()) + .distanceType(baseSortParam.getGeoDistanceType()) + .unit(baseSortParam.getUnit()) + )); + case CUSTOMIZE -> baseSortParam.getSortBuilder(); + }; } @@ -665,14 +661,15 @@ public class WrapperProcessor { * * @param wrapper 参数包装类 * @param mappingColumnMap 字段映射map + * @param entityInfo 索引信息 * @param searchSourceBuilder 查询参数建造者 */ private static void setAggregations(Wrapper wrapper, Map mappingColumnMap, - SearchRequest.Builder searchSourceBuilder) { + EntityInfo entityInfo, SearchRequest.Builder searchSourceBuilder) { // 设置折叠(去重)字段 Optional.ofNullable(wrapper.distinctField) .ifPresent(distinctField -> { - String realField = getRealField(distinctField, mappingColumnMap); + String realField = getRealField(distinctField, mappingColumnMap, entityInfo); searchSourceBuilder.collapse(x -> x.field(realField)); searchSourceBuilder.aggregations(REPEAT_NUM_KEY, x -> x.cardinality(y -> y.field(realField))); }); @@ -688,7 +685,7 @@ public class WrapperProcessor { Aggregation.Builder.ContainerBuilder root = null; Aggregation.Builder.ContainerBuilder cursor = null; for (AggregationParam aggParam : aggregationParamList) { - String realField = getRealField(aggParam.getField(), mappingColumnMap); + String realField = getRealField(aggParam.getField(), mappingColumnMap, entityInfo); Aggregation.Builder.ContainerBuilder builder = getRealAggregationBuilder( aggParam.getAggregationType(), realField, wrapper.size, wrapper.bucketOrders); // 解决同一个字段聚合多次,如min(starNum), max(starNum) 字段名重复问题 diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/FieldUtils.java b/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/FieldUtils.java index be2f3a0f..84689553 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/FieldUtils.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/toolkit/FieldUtils.java @@ -7,6 +7,7 @@ import org.dromara.easyes.common.constants.BaseEsConstants; import org.dromara.easyes.common.params.SFunction; import org.dromara.easyes.common.property.GlobalConfig; import org.dromara.easyes.common.utils.StringUtils; +import org.dromara.easyes.core.biz.EntityInfo; import org.dromara.easyes.core.cache.GlobalConfigCache; import java.lang.invoke.MethodHandle; @@ -19,6 +20,7 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +import static org.dromara.easyes.common.constants.BaseEsConstants.DEFAULT_ES_ID_NAME; import static org.dromara.easyes.common.constants.BaseEsConstants.KEYWORD_SUFFIX; /** @@ -151,7 +153,7 @@ public class FieldUtils { * @return 首字母大写后的结果 */ public static String firstToUpperCase(String param) { - if (Objects.isNull(param) || "".equals(param)) { + if (Objects.isNull(param) || param.isEmpty()) { return ""; } return param.substring(0, 1).toUpperCase() + param.substring(1); @@ -162,12 +164,25 @@ public class FieldUtils { * * @param field 原字段名 * @param mappingColumnMap 字段映射关系map + * @param entityInfo 索引信息 * @return 实际字段名 */ - public static String getRealField(String field, Map mappingColumnMap) { + public static String getRealField(String field, Map mappingColumnMap, EntityInfo entityInfo) { String customField = mappingColumnMap.get(field); if (Objects.nonNull(customField)) { - return customField; + if (entityInfo.isId2Source()) { + return customField; + } + // 直接用_id去查询, 但是有些版本需要开启集群配置: indices.id_field_data.enabled + /* + * PUT /_cluster/settings + * { + * "persistent": { + * "indices.id_field_data.enabled": true + * } + * } + */ + return entityInfo.getKeyProperty().equals(field) ? DEFAULT_ES_ID_NAME : customField; } else { GlobalConfig.DbConfig dbConfig = GlobalConfigCache.getGlobalConfig().getDbConfig(); if (dbConfig.isMapUnderscoreToCamelCase()) { @@ -184,13 +199,19 @@ public class FieldUtils { * @param field 字段 * @param fieldTypeMap 字段与es字段类型映射 * @param mappingColumnMap 实体字段与es实际字段映射 + * @param entityInfo 索引信息 * @return 最终的字段 */ - public static String getRealFieldAndSuffix(String field, Map fieldTypeMap, Map mappingColumnMap) { + public static String getRealFieldAndSuffix( + String field, + Map fieldTypeMap, + Map mappingColumnMap, + EntityInfo entityInfo + ) { GlobalConfig.DbConfig dbConfig = GlobalConfigCache.getGlobalConfig().getDbConfig(); - String realField = getRealField(field, mappingColumnMap); + String realField = getRealField(field, mappingColumnMap, entityInfo); String fieldType = fieldTypeMap.get(field); - boolean addSuffix = dbConfig.isSmartAddKeywordSuffix() && FieldType.KEYWORD_TEXT.getType().equals(fieldType); + boolean addSuffix = dbConfig.isSmartAddKeywordSuffix() && FieldType.KEYWORD_TEXT.getType().equals(fieldType) && !DEFAULT_ES_ID_NAME.equals(realField); if (addSuffix) { return realField + KEYWORD_SUFFIX; } @@ -224,11 +245,12 @@ public class FieldUtils { * * @param fields 原字段名数组 * @param mappingColumnMap 字段映射关系map + * @param entityInfo 索引信息 * @return 实际字段数组 */ - public static List getRealFields(String[] fields, Map mappingColumnMap) { + public static List getRealFields(String[] fields, Map mappingColumnMap, EntityInfo entityInfo) { return Arrays.stream(fields) - .map(field -> getRealField(field, mappingColumnMap)) + .map(field -> getRealField(field, mappingColumnMap, entityInfo)) .collect(Collectors.toList()); } @@ -237,11 +259,12 @@ public class FieldUtils { * * @param fields 原字段名数组 * @param mappingColumnMap 字段映射关系map + * @param entityInfo 索引信息 * @return 实际字段数组 */ - public static List getRealFields(List fields, Map mappingColumnMap) { + public static List getRealFields(List fields, Map mappingColumnMap, EntityInfo entityInfo) { return fields.stream() - .map(field -> getRealField(field, mappingColumnMap)) + .map(field -> getRealField(field, mappingColumnMap, entityInfo)) .collect(Collectors.toList()); } diff --git a/easy-es-solon-test/src/main/java/org/dromara/easyes/test/entity/Document.java b/easy-es-solon-test/src/main/java/org/dromara/easyes/test/entity/Document.java index 1aa71219..c2fe55a8 100644 --- a/easy-es-solon-test/src/main/java/org/dromara/easyes/test/entity/Document.java +++ b/easy-es-solon-test/src/main/java/org/dromara/easyes/test/entity/Document.java @@ -2,6 +2,7 @@ package org.dromara.easyes.test.entity; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import org.dromara.easyes.annotation.*; import org.dromara.easyes.annotation.rely.*; @@ -23,6 +24,7 @@ import java.util.List; *

* Copyright © 2021 xpc1024 All Rights Reserved **/ +@EqualsAndHashCode(callSuper = false) @Data @Accessors(chain = true) @Settings(shardsNum = 3, replicasNum = 2, settingsProvider = MySettingsProvider.class) diff --git a/easy-es-solon-test/src/test/java/org/dromara/easyes/test/all/AllTest.java b/easy-es-solon-test/src/test/java/org/dromara/easyes/test/all/AllTest.java index deb6accc..e8ca09e2 100644 --- a/easy-es-solon-test/src/test/java/org/dromara/easyes/test/all/AllTest.java +++ b/easy-es-solon-test/src/test/java/org/dromara/easyes/test/all/AllTest.java @@ -10,7 +10,6 @@ import co.elastic.clients.elasticsearch.core.SearchRequest; import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.json.JsonData; import co.elastic.clients.transport.rest_client.RestClientOptions; -import org.dromara.easyes.common.constants.BaseEsConstants; import org.dromara.easyes.core.biz.EntityInfo; import org.dromara.easyes.core.biz.EsPageInfo; import org.dromara.easyes.core.biz.OrderByParam; @@ -739,10 +738,11 @@ public class AllTest { @Test @Order(60) public void testSort() { + EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(Document.class); String realField = FieldUtils.getRealField( FieldUtils.val(Document::getStarNum), - EntityInfoHelper.getEntityInfo(Document.class).getMappingColumnMap() - ); + entityInfo.getMappingColumnMap(), + entityInfo); LambdaEsQueryWrapper wrapper = new LambdaEsQueryWrapper<>(); wrapper.match(Document::getCreator, "老汉"); @@ -940,40 +940,40 @@ public class AllTest { Assertions.assertTrue(success); } - // 4.删除 - @Test - @Order(76) - public void testDeleteById() { - int count = documentMapper.deleteById("1"); - Assertions.assertEquals(1, count); - } - - @Test - @Order(77) - public void testDeleteBatchIds() { - List idList = Arrays.asList("2", "3", "4"); - int count = documentMapper.deleteBatchIds(idList); - Assertions.assertEquals(3, count); - } - - @Test - @Order(78) - public void testDeleteByWrapper() { - LambdaEsQueryWrapper wrapper = new LambdaEsQueryWrapper<>(); - wrapper.match(Document::getCreator, "老汉"); - - int count = documentMapper.delete(wrapper); - Assertions.assertEquals(18, count); - } - - @Test - @Order(80) - public void testDeleteIndex() { - boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName()); - boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX); - Assertions.assertTrue(deleted); - Assertions.assertTrue(lockDeleted); - } +// // 4.删除 +// @Test +// @Order(76) +// public void testDeleteById() { +// int count = documentMapper.deleteById("1"); +// Assertions.assertEquals(1, count); +// } +// +// @Test +// @Order(77) +// public void testDeleteBatchIds() { +// List idList = Arrays.asList("2", "3", "4"); +// int count = documentMapper.deleteBatchIds(idList); +// Assertions.assertEquals(3, count); +// } +// +// @Test +// @Order(78) +// public void testDeleteByWrapper() { +// LambdaEsQueryWrapper wrapper = new LambdaEsQueryWrapper<>(); +// wrapper.match(Document::getCreator, "老汉"); +// +// int count = documentMapper.delete(wrapper); +// Assertions.assertEquals(18, count); +// } +// +// @Test +// @Order(80) +// public void testDeleteIndex() { +// boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName()); +// boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX); +// Assertions.assertTrue(deleted); +// Assertions.assertTrue(lockDeleted); +// } @Test @Order(79) diff --git a/easy-es-spring-test/src/test/java/org/dromara/easyes/test/all/XmlScannerAllTest.java b/easy-es-spring-test/src/test/java/org/dromara/easyes/test/all/XmlScannerAllTest.java index 2c588961..bcfa2c8e 100644 --- a/easy-es-spring-test/src/test/java/org/dromara/easyes/test/all/XmlScannerAllTest.java +++ b/easy-es-spring-test/src/test/java/org/dromara/easyes/test/all/XmlScannerAllTest.java @@ -757,7 +757,7 @@ public class XmlScannerAllTest { FieldSortBuilder fieldSortBuilder = SortBuilders. fieldSort(FieldUtils.getRealField( FieldUtils.val(Document::getStarNum), - EntityInfoHelper.getEntityInfo(Document.class).getMappingColumnMap())); + EntityInfoHelper.getEntityInfo(Document.class).getMappingColumnMap(), entityInfo.getKeyProperty())); fieldSortBuilder.order(SortOrder.Desc); wrapper.sort(fieldSortBuilder); List documents = documentMapper.selectList(wrapper); diff --git a/easy-es-springboot-test/src/test/java/org/dromara/easyes/test/all/AllTest.java b/easy-es-springboot-test/src/test/java/org/dromara/easyes/test/all/AllTest.java index 33e709ac..d2a5134f 100644 --- a/easy-es-springboot-test/src/test/java/org/dromara/easyes/test/all/AllTest.java +++ b/easy-es-springboot-test/src/test/java/org/dromara/easyes/test/all/AllTest.java @@ -759,7 +759,7 @@ public class AllTest { FieldSortBuilder fieldSortBuilder = SortBuilders. fieldSort(FieldUtils.getRealField( FieldUtils.val(Document::getStarNum), - EntityInfoHelper.getEntityInfo(Document.class).getMappingColumnMap())); + EntityInfoHelper.getEntityInfo(Document.class).getMappingColumnMap(), entityInfo.getKeyProperty())); fieldSortBuilder.order(SortOrder.Desc); wrapper.sort(fieldSortBuilder); List documents = documentMapper.selectList(wrapper);