新增copy_to功能及是否index功能
兼容es8.x
This commit is contained in:
xpc 2025-02-01 19:14:47 +08:00
parent 7c626e0143
commit ae6b377c7c
10 changed files with 63 additions and 14 deletions

View File

@ -1,7 +1,10 @@
package org.dromara.easyes.annotation;
import org.dromara.easyes.annotation.rely.*;
import org.dromara.easyes.annotation.rely.Analyzer;
import org.dromara.easyes.annotation.rely.DefaultNestedClass;
import org.dromara.easyes.annotation.rely.FieldStrategy;
import org.dromara.easyes.annotation.rely.FieldType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -30,6 +33,20 @@ public @interface IndexField {
*/
boolean exist() default true;
/**
* 是否参与搜索考虑到文档的部分字段在有些场景下不参与搜索只做展示
*
* @return 是否设置可聚合
*/
boolean index() default true;
/**
* 用于将多个字段的值复制到一个新的字段中以便在查询时可以简化查询语句提高检索效率
*
* @return 复制当前字段至指定字段中
*/
String copyTo() default "";
/**
* 字段在es索引中的类型,建议根据业务场景指定,若不指定则由本框架自动推断
*

View File

@ -62,7 +62,9 @@ public enum FieldType {
TOKEN("token"),
ATTACHMENT("attachment"),
PERCOLATOR("percolator"),
DENSE_VECTOR("dense_vector");
DENSE_VECTOR("dense_vector"),
INDEX("index"),
COPY_TO("copy_to");
private String type;

View File

@ -63,6 +63,14 @@ public class EsIndexParam {
* 字段最大索引长度 默认256
*/
private Integer ignoreAbove;
/**
* 是否索引
*/
private boolean index;
/**
* 复制属性
*/
private String copyTo;
/**
* 内部字段列表

View File

@ -16,11 +16,11 @@ 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.OrderTypeEnum;
import org.dromara.easyes.common.property.GlobalConfig;
import org.dromara.easyes.common.utils.*;
import org.dromara.easyes.core.biz.*;
import org.dromara.easyes.core.cache.BaseCache;
import org.dromara.easyes.core.cache.GlobalConfigCache;
import org.dromara.easyes.common.property.GlobalConfig;
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
import org.dromara.easyes.core.toolkit.FieldUtils;
import org.dromara.easyes.core.toolkit.IndexUtils;
@ -49,7 +49,6 @@ import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.client.indices.GetIndexResponse;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
@ -62,6 +61,7 @@ import org.elasticsearch.search.aggregations.metrics.ParsedCardinality;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;
import java.io.Serializable;
@ -274,7 +274,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
boolean notSort = CollectionUtils.isEmpty(wrapper.baseSortParams) && CollectionUtils.isEmpty(wrapper.orderByParams);
if (notSort) {
// 混合查询中 排序
List<SortBuilder<?>> sorts = Objects.nonNull(wrapper.searchSourceBuilder) ? wrapper.searchSourceBuilder.sorts() : new ArrayList<>();
List<SortBuilder<?>> sorts = Objects.nonNull(wrapper.searchSourceBuilder) ? wrapper.searchSourceBuilder.sorts() : Collections.emptyList();
if (CollectionUtils.isEmpty(sorts)) {
throw ExceptionUtils.eee("sortParamList cannot be empty");
}

View File

@ -9,10 +9,10 @@ import org.dromara.easyes.annotation.rely.FieldType;
import org.dromara.easyes.common.constants.BaseEsConstants;
import org.dromara.easyes.common.enums.JdkDataTypeEnum;
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
import org.dromara.easyes.common.property.GlobalConfig;
import org.dromara.easyes.common.utils.*;
import org.dromara.easyes.core.biz.*;
import org.dromara.easyes.core.cache.GlobalConfigCache;
import org.dromara.easyes.common.property.GlobalConfig;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
@ -28,12 +28,12 @@ import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.ReindexRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;
import java.util.*;
@ -80,6 +80,15 @@ public class IndexUtils {
* dims索引字段名
*/
private static final String DIMS_KEY;
/**
* 是否索引
*/
private static final String INDEX_KEY;
/**
* 复制索引字段名
*/
private static final String COPY_TO_KEY;
/**
* 急切全局系数,join父子类型默认字段
*/
@ -93,6 +102,8 @@ public class IndexUtils {
LOWERCASE = "lowercase";
DIMS_KEY = "dims";
EAGER_GLOBAL_ORDINALS = "eager_global_ordinals";
INDEX_KEY = "index";
COPY_TO_KEY = "copy_to";
}
/**
@ -487,6 +498,16 @@ public class IndexUtils {
// 设置权重
Optional.ofNullable(indexParam.getBoost()).ifPresent(boost -> info.put(BOOST_KEY, indexParam.getBoost()));
// 是否索引
if (!indexParam.isIndex()) {
info.put(INDEX_KEY, indexParam.isIndex());
}
// 复制
if (StringUtils.isNotBlank(indexParam.getCopyTo())) {
info.put(COPY_TO_KEY, indexParam.getCopyTo());
}
// 设置嵌套类型
if (FieldType.NESTED.getType().equals(indexParam.getFieldType())) {
// 递归

View File

@ -9,10 +9,10 @@ import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;

View File

@ -32,8 +32,8 @@
<properties>
<java.version>1.8</java.version>
<lombok.version>1.18.28</lombok.version>
<es-rest-high-level-client.version>7.14.0</es-rest-high-level-client.version>
<es.version>7.14.0</es.version>
<es-rest-high-level-client.version>7.17.8</es-rest-high-level-client.version>
<es.version>7.17.8</es.version>
<fastjson.version>1.2.83</fastjson.version>
<codec.version>1.13</codec.version>
<spring-boot.version>2.6.10</spring-boot.version>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>../easy-es-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</parent>
<artifactId>easy-es-solon-test</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>../easy-es-parent</relativePath>
</parent>
@ -15,6 +15,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<junit-jupiter-engine.version>5.4.0</junit-jupiter-engine.version>
</properties>
<dependencies>
@ -38,7 +39,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<version>${junit-jupiter-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>