mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-07 17:48:42 +08:00
v2.1.0
新增copy_to功能及是否index功能 兼容es8.x
This commit is contained in:
parent
7c626e0143
commit
ae6b377c7c
@ -1,7 +1,10 @@
|
|||||||
package org.dromara.easyes.annotation;
|
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.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -30,6 +33,20 @@ public @interface IndexField {
|
|||||||
*/
|
*/
|
||||||
boolean exist() default true;
|
boolean exist() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否参与搜索,考虑到文档的部分字段,在有些场景下,不参与搜索,只做展示
|
||||||
|
*
|
||||||
|
* @return 是否设置可聚合
|
||||||
|
*/
|
||||||
|
boolean index() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于将多个字段的值复制到一个新的字段中,以便在查询时可以简化查询语句,提高检索效率
|
||||||
|
*
|
||||||
|
* @return 复制当前字段至指定字段中
|
||||||
|
*/
|
||||||
|
String copyTo() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段在es索引中的类型,建议根据业务场景指定,若不指定则由本框架自动推断
|
* 字段在es索引中的类型,建议根据业务场景指定,若不指定则由本框架自动推断
|
||||||
*
|
*
|
||||||
|
|||||||
@ -62,7 +62,9 @@ public enum FieldType {
|
|||||||
TOKEN("token"),
|
TOKEN("token"),
|
||||||
ATTACHMENT("attachment"),
|
ATTACHMENT("attachment"),
|
||||||
PERCOLATOR("percolator"),
|
PERCOLATOR("percolator"),
|
||||||
DENSE_VECTOR("dense_vector");
|
DENSE_VECTOR("dense_vector"),
|
||||||
|
INDEX("index"),
|
||||||
|
COPY_TO("copy_to");
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,14 @@ public class EsIndexParam {
|
|||||||
* 字段最大索引长度 默认256
|
* 字段最大索引长度 默认256
|
||||||
*/
|
*/
|
||||||
private Integer ignoreAbove;
|
private Integer ignoreAbove;
|
||||||
|
/**
|
||||||
|
* 是否索引
|
||||||
|
*/
|
||||||
|
private boolean index;
|
||||||
|
/**
|
||||||
|
* 复制属性
|
||||||
|
*/
|
||||||
|
private String copyTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内部字段列表
|
* 内部字段列表
|
||||||
|
|||||||
@ -16,11 +16,11 @@ 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.OrderTypeEnum;
|
import org.dromara.easyes.common.enums.OrderTypeEnum;
|
||||||
|
import org.dromara.easyes.common.property.GlobalConfig;
|
||||||
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;
|
||||||
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
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.EntityInfoHelper;
|
||||||
import org.dromara.easyes.core.toolkit.FieldUtils;
|
import org.dromara.easyes.core.toolkit.FieldUtils;
|
||||||
import org.dromara.easyes.core.toolkit.IndexUtils;
|
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.GetIndexResponse;
|
||||||
import org.elasticsearch.client.indices.PutMappingRequest;
|
import org.elasticsearch.client.indices.PutMappingRequest;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
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.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
import org.elasticsearch.search.sort.SortBuilder;
|
||||||
|
import org.elasticsearch.xcontent.XContentType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
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);
|
boolean notSort = CollectionUtils.isEmpty(wrapper.baseSortParams) && CollectionUtils.isEmpty(wrapper.orderByParams);
|
||||||
if (notSort) {
|
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)) {
|
if (CollectionUtils.isEmpty(sorts)) {
|
||||||
throw ExceptionUtils.eee("sortParamList cannot be empty");
|
throw ExceptionUtils.eee("sortParamList cannot be empty");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,10 @@ import org.dromara.easyes.annotation.rely.FieldType;
|
|||||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||||
import org.dromara.easyes.common.enums.JdkDataTypeEnum;
|
import org.dromara.easyes.common.enums.JdkDataTypeEnum;
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||||
|
import org.dromara.easyes.common.property.GlobalConfig;
|
||||||
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.GlobalConfigCache;
|
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.Alias;
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
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.CreateIndexResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
import org.elasticsearch.client.indices.GetIndexResponse;
|
import org.elasticsearch.client.indices.GetIndexResponse;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.core.TimeValue;
|
import org.elasticsearch.core.TimeValue;
|
||||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||||
import org.elasticsearch.index.reindex.ReindexRequest;
|
import org.elasticsearch.index.reindex.ReindexRequest;
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
|
import org.elasticsearch.xcontent.XContentType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -80,6 +80,15 @@ public class IndexUtils {
|
|||||||
* dims索引字段名
|
* dims索引字段名
|
||||||
*/
|
*/
|
||||||
private static final String DIMS_KEY;
|
private static final String DIMS_KEY;
|
||||||
|
/**
|
||||||
|
* 是否索引
|
||||||
|
*/
|
||||||
|
private static final String INDEX_KEY;
|
||||||
|
/**
|
||||||
|
* 复制索引字段名
|
||||||
|
*/
|
||||||
|
private static final String COPY_TO_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 急切全局系数,join父子类型默认字段
|
* 急切全局系数,join父子类型默认字段
|
||||||
*/
|
*/
|
||||||
@ -93,6 +102,8 @@ public class IndexUtils {
|
|||||||
LOWERCASE = "lowercase";
|
LOWERCASE = "lowercase";
|
||||||
DIMS_KEY = "dims";
|
DIMS_KEY = "dims";
|
||||||
EAGER_GLOBAL_ORDINALS = "eager_global_ordinals";
|
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()));
|
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())) {
|
if (FieldType.NESTED.getType().equals(indexParam.getFieldType())) {
|
||||||
// 递归
|
// 递归
|
||||||
|
|||||||
@ -9,10 +9,10 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.client.RequestOptions;
|
import org.elasticsearch.client.RequestOptions;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
|
import org.elasticsearch.xcontent.XContentType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|||||||
@ -32,8 +32,8 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<lombok.version>1.18.28</lombok.version>
|
<lombok.version>1.18.28</lombok.version>
|
||||||
<es-rest-high-level-client.version>7.14.0</es-rest-high-level-client.version>
|
<es-rest-high-level-client.version>7.17.8</es-rest-high-level-client.version>
|
||||||
<es.version>7.14.0</es.version>
|
<es.version>7.17.8</es.version>
|
||||||
<fastjson.version>1.2.83</fastjson.version>
|
<fastjson.version>1.2.83</fastjson.version>
|
||||||
<codec.version>1.13</codec.version>
|
<codec.version>1.13</codec.version>
|
||||||
<spring-boot.version>2.6.10</spring-boot.version>
|
<spring-boot.version>2.6.10</spring-boot.version>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.easy-es</groupId>
|
<groupId>org.dromara.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.1.0</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.easy-es</groupId>
|
<groupId>org.dromara.easy-es</groupId>
|
||||||
<artifactId>easy-es</artifactId>
|
<artifactId>easy-es</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>easy-es-solon-test</artifactId>
|
<artifactId>easy-es-solon-test</artifactId>
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.easy-es</groupId>
|
<groupId>org.dromara.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.1.0</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -15,6 +15,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<junit-jupiter-engine.version>5.4.0</junit-jupiter-engine.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -38,7 +39,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>${junit-jupiter-engine.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user