mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
commit
575bc78292
35
README.md
35
README.md
@ -5,14 +5,14 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
为简化开发工作、提高生产效率而生
|
||||
您的Star是我继续前进的动力,如果喜欢EE请右上角帮忙点亮星星⭐!
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*">
|
||||
<img alt="maven" src="https://img.shields.io/github/v/release/xpc1024/easy-es?include_prereleases&logo=xpc&style=plastic">
|
||||
</a>
|
||||
<a href="https://www.murphysec.com/dr/1hRHmuH0DE3RYL9uE0" alt="OSCS Status"><img src="https://www.oscs1024.com/platform/badge/dromara/easy-es.git.svg?size=small"/></a>
|
||||
<a href="https://www.murphysec.com/dr/htY0sMYDQaDn4X8iXp" alt="OSCS Status"><img src="https://www.oscs1024.com/platform/badge/dromara/easy-es.git.svg?size=small"/></a>
|
||||
<a href="https://www.apache.org/licenses/LICENSE-2.0">
|
||||
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
|
||||
</a>
|
||||
@ -44,7 +44,7 @@ Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动
|
||||
|
||||
底层采用Es官方提供的RestHighLevelClient,保证其原生性能及拓展性.
|
||||
|
||||
技术讨论 QQ 群 :247637156 群内可免费领取 颈椎保护 | 增肌 | 减脂 等健身计划
|
||||
技术讨论 QQ 群 :729148550 群内可在群文件中免费领取 颈椎保护 | 增肌 | 减脂 等健身计划 无套路
|
||||
|
||||
微信群请先添加作者微信,由作者拉入 (亦可咨询健身问题,作者是健身教练)
|
||||
|
||||
@ -144,15 +144,6 @@ compile group: 'cn.easy-es', name: 'easy-es-boot-starter', version: 'Latest Vers
|
||||
|
||||
[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
# 捐赠 | Donate
|
||||
---
|
||||
|
||||
[捐赠记录,感谢你们的支持!](https://easy-es.cn/pages/b52ac5/)
|
||||
|
||||
> 您的支持是鼓励我们前行的动力,无论金额多少都足够表达您这份心意。
|
||||
|
||||
> 如果您愿意捐赠本项目,推荐直接在右下方通过Gitee直接捐赠.
|
||||
|
||||
# 关注我 | About Me
|
||||
---
|
||||
|
||||
@ -162,4 +153,22 @@ QQ | 微信:252645816
|
||||
|
||||
# 知识星球 | Planet Of Knowledge
|
||||
---
|
||||
<img alt="zsxq" src="https://iknow.hs.net/9038b7ab-c0d9-4a87-9492-e839907a8978.png">
|
||||
<img alt="zsxq" src="https://iknow.hs.net/9038b7ab-c0d9-4a87-9492-e839907a8978.png">
|
||||
|
||||
# 捐赠 | Donate
|
||||
---
|
||||
|
||||
[捐赠记录,感谢你们的支持!](https://easy-es.cn/pages/b52ac5/)
|
||||
|
||||
> 您的支持是鼓励我们前行的动力,无论金额多少都足够表达您这份心意。
|
||||
|
||||
> 如果您愿意捐赠本项目,推荐直接在右下方通过Gitee直接捐赠.
|
||||
|
||||
# 赞助商 | Sponsor
|
||||
---
|
||||
|
||||
> 如果您想支持我们,奈何囊中羞涩,没事,您可以花30秒借花献佛,点击下方链接进入注册,则该赞助商会代您捐赠一笔小钱给社区开发者们买包辣条。
|
||||
|
||||
<a href="http://apifox.cn/a103easyse">
|
||||
<img alt="ad" src="https://iknow.hs.net/a26897a9-d408-4985-9ed6-b3180ea6ed98.png">
|
||||
</a>
|
||||
71
README_EN.md
71
README_EN.md
@ -12,7 +12,7 @@
|
||||
<a href="https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*">
|
||||
<img alt="maven" src="https://img.shields.io/github/v/release/xpc1024/easy-es?include_prereleases&logo=xpc&style=plastic">
|
||||
</a>
|
||||
<a href="https://www.murphysec.com/dr/1hRHmuH0DE3RYL9uE0" alt="OSCS Status"><img src="https://www.oscs1024.com/platform/badge/dromara/easy-es.git.svg?size=small"/></a>
|
||||
<a href="https://www.murphysec.com/dr/htY0sMYDQaDn4X8iXp" alt="OSCS Status"><img src="https://www.oscs1024.com/platform/badge/dromara/easy-es.git.svg?size=small"/></a>
|
||||
<a href="https://www.apache.org/licenses/LICENSE-2.0">
|
||||
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
|
||||
</a>
|
||||
@ -137,41 +137,44 @@ String indexName = "document";
|
||||
---
|
||||

|
||||
|
||||
## Syntax comparison with MySQL
|
||||
## MySQL Easy-Es and Es syntax comparison table
|
||||
---
|
||||
| MySQL | Easy-Es |
|
||||
| ---- | ---- |
|
||||
| and | and |
|
||||
| or | or |
|
||||
| = | eq |
|
||||
| != | ne|
|
||||
| > | gt |
|
||||
| >= | ge |
|
||||
| < | lt |
|
||||
| <= | le |
|
||||
| like '%field%' | like |
|
||||
| not like '%field%' |notLike|
|
||||
| like '%field' | likeLeft|
|
||||
| like 'field%' | likeRight |
|
||||
| between | between |
|
||||
| notBetween | notBetween |
|
||||
| is null | isNull |
|
||||
| is notNull | isNotNull |
|
||||
| in | in |
|
||||
| not in | notIn |
|
||||
| group by | groupBy |
|
||||
| order by | orderBy |
|
||||
|min |min |
|
||||
|max |max |
|
||||
|avg |avg |
|
||||
|sum |sum |
|
||||
|sum |sum |
|
||||
| - | orderByAsc |
|
||||
| - | orderByDesc |
|
||||
| - | match |
|
||||
|- |highLight |
|
||||
| ... | ... |
|
||||
|
||||
| MySQL | Easy-Es | Es-DSL/Es java api|
|
||||
| --- | --- |--- |
|
||||
| and | and |must|
|
||||
| or | or | should|
|
||||
| = | eq | term|
|
||||
| != | ne | boolQueryBuilder.mustNot(queryBuilder)|
|
||||
| > | gt | QueryBuilders.rangeQuery('es field').gt()|
|
||||
| >= | ge | .rangeQuery('es field').gte()|
|
||||
| < | lt | .rangeQuery('es field').lt() |
|
||||
| <= | le | .rangeQuery('es field').lte()|
|
||||
| like '%field%' | like | QueryBuilders.wildcardQuery(field,*value*)|
|
||||
| not like '%field%' | notLike | must not wildcardQuery(field,*value*)|
|
||||
| like '%field' | likeLeft | QueryBuilders.wildcardQuery(field,*value)|
|
||||
| like 'field%' | likeRight | QueryBuilders.wildcardQuery(field,value*)|
|
||||
| between | between | QueryBuilders.rangeQuery('es field').from(xx).to(xx) |
|
||||
| notBetween | notBetween | must not QueryBuilders.rangeQuery('es field').from(xx).to(xx)|
|
||||
| is null | isNull | must not QueryBuilders.existsQuery(field) |
|
||||
| is notNull | isNotNull | QueryBuilders.existsQuery(field)|
|
||||
| in | in | QueryBuilders.termsQuery(" xx es field", xx)|
|
||||
| not in | notIn | must not QueryBuilders.termsQuery(" xx es field", xx)|
|
||||
| group by | groupBy | AggregationBuilders.terms()|
|
||||
| order by | orderBy | fieldSortBuilder.order(ASC/DESC)|
|
||||
| min | min | AggregationBuilders.min|
|
||||
| max | max |AggregationBuilders.max|
|
||||
| avg | avg |AggregationBuilders.avg|
|
||||
| sum | sum |AggregationBuilders.sum|
|
||||
| order by xxx asc | orderByAsc | fieldSortBuilder.order(SortOrder.ASC)|
|
||||
| order by xxx desc | orderByDesc |fieldSortBuilder.order(SortOrder.DESC)|
|
||||
| - | match |matchQuery|
|
||||
| - | matchPhrase |QueryBuilders.matchPhraseQuery|
|
||||
| - | matchPrefix |QueryBuilders.matchPhrasePrefixQuery|
|
||||
| - | queryStringQuery |QueryBuilders.queryStringQuery|
|
||||
| select * | matchAllQuery |QueryBuilders.matchAllQuery()|
|
||||
| - | highLight |HighlightBuilder.Field |
|
||||
| ... | ... | ...|
|
||||
---
|
||||
|
||||
## Donate
|
||||
|
||||
BIN
dist/img/640x240.png
vendored
Normal file
BIN
dist/img/640x240.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 598 KiB |
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -18,10 +18,4 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,15 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author lyy
|
||||
*/
|
||||
@Target({ElementType.TYPE,ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface EsDS {
|
||||
|
||||
String value();
|
||||
}
|
||||
@ -1,14 +1,15 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
|
||||
import cn.easyes.common.enums.HighLightTypeEnum;
|
||||
import cn.easyes.annotation.rely.HighLightTypeEnum;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.*;
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.*;
|
||||
|
||||
|
||||
/**
|
||||
* 字段注解
|
||||
@ -45,8 +46,10 @@ public @interface HighLight {
|
||||
* @return 高亮后置标签
|
||||
*/
|
||||
String postTag() default HIGH_LIGHT_POST_TAG;
|
||||
|
||||
/**
|
||||
* 使用的高亮模式
|
||||
*
|
||||
* @return 高亮模式
|
||||
*/
|
||||
HighLightTypeEnum highLightType() default HighLightTypeEnum.UNIFIED;
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.params.DefaultNestedClass;
|
||||
import cn.easyes.common.params.JoinField;
|
||||
|
||||
import cn.easyes.annotation.rely.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
package cn.easyes.annotation;
|
||||
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.common.params.DefaultChildClass;
|
||||
import cn.easyes.common.params.JoinField;
|
||||
import cn.easyes.annotation.rely.DefaultChildClass;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.*;
|
||||
|
||||
/**
|
||||
* 索引注解
|
||||
* <p>
|
||||
@ -29,21 +29,28 @@ public @interface IndexName {
|
||||
*
|
||||
* @return 默认为1
|
||||
*/
|
||||
int shardsNum() default BaseEsConstants.DEFAULT_SHARDS;
|
||||
int shardsNum() default DEFAULT_SHARDS;
|
||||
|
||||
/**
|
||||
* 副本数
|
||||
*
|
||||
* @return 默认为1
|
||||
*/
|
||||
int replicasNum() default BaseEsConstants.DEFAULT_REPLICAS;
|
||||
int replicasNum() default DEFAULT_REPLICAS;
|
||||
|
||||
/**
|
||||
* 默认最大返回数
|
||||
*
|
||||
* @return 默认1w条
|
||||
*/
|
||||
int maxResultWindow() default DEFAULT_MAX_RESULT_WINDOW;
|
||||
|
||||
/**
|
||||
* 索引别名
|
||||
*
|
||||
* @return 别名
|
||||
*/
|
||||
String aliasName() default BaseEsConstants.DEFAULT_ALIAS;
|
||||
String aliasName() default DEFAULT_ALIAS;
|
||||
|
||||
/**
|
||||
* 是否保持使用全局的 tablePrefix 的值
|
||||
@ -67,5 +74,4 @@ public @interface IndexName {
|
||||
* @return 默认子类
|
||||
*/
|
||||
Class<?> childClass() default DefaultChildClass.class;
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.easyes.common.constants;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 分词器 如果不包含用户所需分词器,可自行指定传入字符串
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 注解依赖常量
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public interface AnnotationConstants {
|
||||
/**
|
||||
* 高亮默认前缀标签
|
||||
*/
|
||||
String HIGH_LIGHT_PRE_TAG = "<em>";
|
||||
/**
|
||||
* 高亮默认后缀标签
|
||||
*/
|
||||
String HIGH_LIGHT_POST_TAG = "</em>";
|
||||
/**
|
||||
* 高亮截取默认长度
|
||||
*/
|
||||
int DEFAULT_FRAGMENT_SIZE = 100;
|
||||
/**
|
||||
* 默认分片数
|
||||
*/
|
||||
int DEFAULT_SHARDS = 1;
|
||||
/**
|
||||
* 默认副本数
|
||||
*/
|
||||
int DEFAULT_REPLICAS = 1;
|
||||
/**
|
||||
* 默认最大返回数
|
||||
*/
|
||||
int DEFAULT_MAX_RESULT_WINDOW = 10000;
|
||||
/**
|
||||
* 默认索引别名
|
||||
*/
|
||||
String DEFAULT_ALIAS = "ee_default_alias";
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.easyes.common.params;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 父子类型-默认子类
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.easyes.common.params;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 默认嵌套类
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.easyes.common.enums;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 字段策略枚举
|
||||
@ -1,14 +1,10 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* Es支持的数据类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@AllArgsConstructor
|
||||
public enum FieldType {
|
||||
/**
|
||||
* none Required inside the framework, do not use 框架内部需要,切勿使用,若不慎使用则会被当做keyword类型
|
||||
@ -52,8 +48,14 @@ public enum FieldType {
|
||||
TOKEN("token"),
|
||||
ATTACHMENT("attachment"),
|
||||
PERCOLATOR("percolator");
|
||||
@Getter
|
||||
|
||||
private String type;
|
||||
|
||||
FieldType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,11 @@
|
||||
package cn.easyes.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 高亮类型枚举
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
|
||||
public enum HighLightTypeEnum {
|
||||
/**
|
||||
* unified(通用高亮策略,缺省配置时,默认采用此策略)
|
||||
@ -34,4 +30,12 @@ public enum HighLightTypeEnum {
|
||||
* 聚合类型英文名
|
||||
*/
|
||||
private final String value;
|
||||
|
||||
HighLightTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.easyes.common.enums;
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 主键类型枚举
|
||||
@ -0,0 +1,41 @@
|
||||
package cn.easyes.annotation.rely;
|
||||
|
||||
/**
|
||||
* 父子类型统一关系字段,推荐直接使用此类,不要重复造轮子
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
public class JoinField {
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 父文档id
|
||||
*/
|
||||
private String parent;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JoinField{" +
|
||||
"name='" + name + '\'' +
|
||||
", parent='" + parent + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package cn.easyes.starter.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lyy
|
||||
* @date 2023年03月14日 15:57
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "easy-es.dynamic")
|
||||
public class DynamicEsProperties {
|
||||
|
||||
/**
|
||||
* 配置多动态数据源key datasource id
|
||||
*/
|
||||
private Map<String, EasyEsConfigProperties> datasource = new HashMap<>();
|
||||
}
|
||||
@ -2,6 +2,7 @@ package cn.easyes.starter.config;
|
||||
|
||||
import cn.easyes.common.utils.ExceptionUtils;
|
||||
import cn.easyes.common.utils.RestHighLevelClientBuilder;
|
||||
import cn.easyes.common.utils.RestHighLevelClientUtils;
|
||||
import cn.easyes.common.utils.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
@ -31,12 +32,17 @@ import static cn.easyes.common.constants.BaseEsConstants.DEFAULT_SCHEMA;
|
||||
**/
|
||||
@Configuration
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@EnableConfigurationProperties(EasyEsConfigProperties.class)
|
||||
@EnableConfigurationProperties(value = {DynamicEsProperties.class,EasyEsConfigProperties.class})
|
||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
||||
public class EsAutoConfiguration {
|
||||
@Autowired
|
||||
private EasyEsConfigProperties easyEsConfigProperties;
|
||||
|
||||
@Autowired
|
||||
private DynamicEsProperties dynamicEsProperties;
|
||||
|
||||
private final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
|
||||
/**
|
||||
* 装配RestHighLevelClient
|
||||
*
|
||||
@ -45,6 +51,10 @@ public class EsAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RestHighLevelClient restHighLevelClient() {
|
||||
return restHighLevelClient(easyEsConfigProperties);
|
||||
}
|
||||
|
||||
private RestHighLevelClient restHighLevelClient(EasyEsConfigProperties easyEsConfigProperties){
|
||||
// 处理地址
|
||||
String address = easyEsConfigProperties.getAddress();
|
||||
if (StringUtils.isEmpty(address)) {
|
||||
@ -94,7 +104,8 @@ public class EsAutoConfiguration {
|
||||
Integer connectTimeOut = easyEsConfigProperties.getConnectTimeout();
|
||||
Integer socketTimeOut = easyEsConfigProperties.getSocketTimeout();
|
||||
Integer connectionRequestTimeOut = easyEsConfigProperties.getConnectionRequestTimeout();
|
||||
boolean needSetRequestConfig = Objects.nonNull(connectTimeOut) || Objects.nonNull(connectionRequestTimeOut);
|
||||
boolean needSetRequestConfig = Objects.nonNull(connectTimeOut) || Objects.nonNull(socketTimeOut) ||
|
||||
Objects.nonNull(connectionRequestTimeOut);
|
||||
if (needSetRequestConfig) {
|
||||
builder.setRequestConfigCallback(requestConfigBuilder -> {
|
||||
Optional.ofNullable(connectTimeOut).ifPresent(requestConfigBuilder::setConnectTimeout);
|
||||
@ -108,4 +119,19 @@ public class EsAutoConfiguration {
|
||||
return RestHighLevelClientBuilder.build(builder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public RestHighLevelClientUtils restHighLevelClientUtils(){
|
||||
RestHighLevelClientUtils restHighLevelClientUtils = new RestHighLevelClientUtils();
|
||||
Map<String, EasyEsConfigProperties> datasourceMap = dynamicEsProperties.getDatasource();
|
||||
Map<String, RestHighLevelClient> restHighLevelClientMap = new HashMap<>();
|
||||
for (String key : datasourceMap.keySet()) {
|
||||
EasyEsConfigProperties easyEsConfigProperties = datasourceMap.get(key);
|
||||
restHighLevelClientMap.put(key,restHighLevelClient(easyEsConfigProperties));
|
||||
RestHighLevelClientUtils.registerRestHighLevelClient(key, restHighLevelClient(easyEsConfigProperties));
|
||||
}
|
||||
return restHighLevelClientUtils;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package cn.easyes.starter.register;
|
||||
|
||||
import cn.easyes.annotation.EsDS;
|
||||
import cn.easyes.annotation.Intercepts;
|
||||
import cn.easyes.annotation.rely.DefaultChildClass;
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.params.DefaultChildClass;
|
||||
import cn.easyes.common.utils.LogUtils;
|
||||
import cn.easyes.common.utils.RestHighLevelClientUtils;
|
||||
import cn.easyes.common.utils.TypeUtils;
|
||||
import cn.easyes.core.biz.EntityInfo;
|
||||
import cn.easyes.core.cache.BaseCache;
|
||||
@ -26,6 +28,8 @@ import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.easyes.common.utils.RestHighLevelClientUtils.DEFAULT_DS;
|
||||
|
||||
/**
|
||||
* 代理类
|
||||
* <p>
|
||||
@ -35,7 +39,7 @@ public class MapperFactoryBean<T> implements FactoryBean<T> {
|
||||
private Class<T> mapperInterface;
|
||||
|
||||
@Autowired
|
||||
private RestHighLevelClient client;
|
||||
private RestHighLevelClientUtils restHighLevelClientUtils;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
@ -63,6 +67,12 @@ public class MapperFactoryBean<T> implements FactoryBean<T> {
|
||||
|
||||
// 初始化缓存
|
||||
GlobalConfigCache.setGlobalConfig(esConfigProperties.getGlobalConfig());
|
||||
|
||||
//获取动态数据源
|
||||
EsDS annotation = mapperInterface.getAnnotation(EsDS.class);
|
||||
RestHighLevelClient client = restHighLevelClientUtils.getClient(annotation != null? annotation.value() : DEFAULT_DS);
|
||||
BaseCache.initCache(mapperInterface, entityClass, client);
|
||||
|
||||
BaseCache.initCache(mapperInterface, entityClass, client);
|
||||
|
||||
// 创建代理
|
||||
|
||||
@ -54,8 +54,13 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Res
|
||||
" |___| \\__,_| /__/_ _|__/ _____ |___| /__/_\n" +
|
||||
"_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_| \"\"\"\"|_| |_|\"\"\"\"\"|_|\"\"\"\"\"|\n" +
|
||||
"\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\n" +
|
||||
"----------添加老汉微信:252645816,早日成为肌肉猛男----------->");
|
||||
System.out.println(":: easy-es :: (v:" + versionStr + ")");
|
||||
"------------------------------------------------------>"
|
||||
);
|
||||
System.out.println(":: version :: " + versionStr + " >");
|
||||
System.out.println(":: home :: https://easy-es.cn/ >");
|
||||
System.out.println(":: community :: https://dromara.org/ >");
|
||||
System.out.println(":: wechat :: 252645816, add and become muscle man! >");
|
||||
System.out.println("------------------------------------------------------>");
|
||||
}
|
||||
|
||||
AnnotationAttributes mapperScanAttrs = AnnotationAttributes
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -34,18 +34,7 @@ public interface BaseEsConstants {
|
||||
* 数字-1
|
||||
*/
|
||||
Integer MINUS_ONE = -1;
|
||||
/**
|
||||
* 默认索引别名
|
||||
*/
|
||||
String DEFAULT_ALIAS = "ee_default_alias";
|
||||
/**
|
||||
* 高亮默认前缀标签
|
||||
*/
|
||||
String HIGH_LIGHT_PRE_TAG = "<em>";
|
||||
/**
|
||||
* 高亮默认后缀标签
|
||||
*/
|
||||
String HIGH_LIGHT_POST_TAG = "</em>";
|
||||
|
||||
/**
|
||||
* 默认的当前页码
|
||||
*/
|
||||
@ -102,6 +91,10 @@ public interface BaseEsConstants {
|
||||
* 副本数量字段
|
||||
*/
|
||||
String REPLICAS_FIELD = "index.number_of_replicas";
|
||||
/**
|
||||
* 最大返回个数字段
|
||||
*/
|
||||
String MAX_RESULT_WINDOW_FIELD = "index.max_result_window";
|
||||
/**
|
||||
* 索引特性
|
||||
*/
|
||||
@ -194,14 +187,7 @@ public interface BaseEsConstants {
|
||||
* 初始任务执行延迟
|
||||
*/
|
||||
int INITIAL_DELAY = 30;
|
||||
/**
|
||||
* 默认分片数
|
||||
*/
|
||||
int DEFAULT_SHARDS = 1;
|
||||
/**
|
||||
* 默认副本数
|
||||
*/
|
||||
int DEFAULT_REPLICAS = 1;
|
||||
|
||||
/**
|
||||
* 被折叠的重复数据数量的key
|
||||
*/
|
||||
@ -230,13 +216,13 @@ public interface BaseEsConstants {
|
||||
* 索引权重key
|
||||
*/
|
||||
String BOOST_KEY = "boost";
|
||||
/**
|
||||
* 高亮截取默认长度
|
||||
*/
|
||||
int DEFAULT_FRAGMENT_SIZE = 100;
|
||||
/**
|
||||
* 针对text进行聚合
|
||||
*/
|
||||
String FIELD_DATA = "fielddata";
|
||||
/**
|
||||
* 未知的版本号
|
||||
*/
|
||||
String UNKNOWN = "unknown";
|
||||
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package cn.easyes.common.params;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 父子类型统一关系字段,推荐直接使用此类,不要重复造轮子
|
||||
* <p>
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
public class JoinField {
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 父文档id
|
||||
*/
|
||||
private String parent;
|
||||
}
|
||||
@ -8,6 +8,8 @@ import org.elasticsearch.client.RestHighLevelClient;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.UNKNOWN;
|
||||
|
||||
/**
|
||||
* ee 版本工具类
|
||||
*
|
||||
@ -31,7 +33,7 @@ public class EEVersionUtils {
|
||||
*/
|
||||
public static <T> String getJarVersion(Class<T> objectClass) {
|
||||
return Optional.ofNullable(objectClass.getPackage().getImplementationVersion()).
|
||||
orElse("unknown");
|
||||
orElse(UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -5,15 +5,21 @@ import lombok.NoArgsConstructor;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import static cn.easyes.common.constants.BaseEsConstants.UNKNOWN;
|
||||
|
||||
/**
|
||||
* elasticsearch 构造器
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class RestHighLevelClientBuilder {
|
||||
/**
|
||||
* 支持的版本 目前支持版本为7.xx 推荐7.14.0
|
||||
* 支持的版本 目前支持版本为7.14.0 稳定无漏洞版
|
||||
*/
|
||||
private final static String supportedVersion = "7";
|
||||
private final static String SUPPORTED_JAR_VERSION = "7.14.0";
|
||||
/**
|
||||
* 支持的客户端版本 目前支持7.xx 推荐7.14.0
|
||||
*/
|
||||
private final static String SUPPORTED_CLIENT_VERSION = "7";
|
||||
|
||||
/**
|
||||
* 构建RestHighLevelClient
|
||||
@ -37,19 +43,18 @@ public class RestHighLevelClientBuilder {
|
||||
// 校验jar包版本是否为推荐使用版本
|
||||
String jarVersion = EEVersionUtils.getJarVersion(restHighLevelClient.getClass());
|
||||
LogUtils.formatInfo("Elasticsearch jar version:%s", jarVersion);
|
||||
if (!jarVersion.startsWith(supportedVersion)) {
|
||||
// 这里抛出异常原因是ee强制依赖于jar包版本,jar包版本不对会导致ee异常
|
||||
throw ExceptionUtils.eee("Easy-Es supported elasticsearch jar version is:%s.xx", supportedVersion);
|
||||
if (!jarVersion.equals(SUPPORTED_JAR_VERSION) && !UNKNOWN.equals(jarVersion)) {
|
||||
LogUtils.formatError("Easy-Es supported elasticsearch and restHighLevelClient jar version is:%s ,Please resolve the dependency conflict!", SUPPORTED_JAR_VERSION);
|
||||
}
|
||||
String clientVersion = EEVersionUtils.getClientVersion(restHighLevelClient);
|
||||
LogUtils.formatInfo("Elasticsearch client version:%s", clientVersion);
|
||||
if (!clientVersion.startsWith(supportedVersion)) {
|
||||
if (!clientVersion.startsWith(SUPPORTED_CLIENT_VERSION)) {
|
||||
// 这里校验客户端为非强制,客户端版本非推荐版本对应提醒即可,es会报错提醒
|
||||
LogUtils.formatWarn("Easy-Es supported elasticsearch client version is:%s.xx", supportedVersion);
|
||||
LogUtils.formatWarn("Easy-Es supported elasticsearch client version is:%s.xx", SUPPORTED_CLIENT_VERSION);
|
||||
}
|
||||
if (!jarVersion.equals(clientVersion)) {
|
||||
// 提示jar包与客户端版本不对应,es官方推荐jar包版本对应客户端版本
|
||||
LogUtils.formatWarn("Elasticsearch clientVersion:%s not equals jarVersion:%s", clientVersion, jarVersion);
|
||||
LogUtils.formatWarn("Elasticsearch clientVersion:%s not equals jarVersion:%s, It does not affect your use, but we still recommend keeping it consistent!", clientVersion, jarVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
package cn.easyes.common.utils;
|
||||
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author lyy
|
||||
* @date 2023年03月14日 16:05
|
||||
*/
|
||||
public class RestHighLevelClientUtils {
|
||||
|
||||
public static final String DEFAULT_DS = "DEFAULT_DS";
|
||||
|
||||
private static Map<String, RestHighLevelClient> restHighLevelClientMap = new ConcurrentHashMap<>();
|
||||
|
||||
public RestHighLevelClientUtils() {
|
||||
}
|
||||
|
||||
public static RestHighLevelClient getRestHighLevelClient(String restHighLevelClientId) {
|
||||
if(DEFAULT_DS.equals(restHighLevelClientId)){
|
||||
return restHighLevelClientMap.values().stream().findFirst().get();
|
||||
}
|
||||
RestHighLevelClient restHighLevelClient = restHighLevelClientMap.get(restHighLevelClientId);
|
||||
if(restHighLevelClient == null){
|
||||
ExceptionUtils.eee("找不到RestHighLevelClient,restHighLevelClientId:",restHighLevelClientId);
|
||||
|
||||
}
|
||||
return restHighLevelClient;
|
||||
}
|
||||
|
||||
public RestHighLevelClient getClient(String restHighLevelClientId) {
|
||||
return RestHighLevelClientUtils.getRestHighLevelClient(restHighLevelClientId);
|
||||
}
|
||||
|
||||
public static void registerRestHighLevelClient(String restHighLevelClientId, RestHighLevelClient restHighLevelClient) {
|
||||
RestHighLevelClientUtils.restHighLevelClientMap.put(restHighLevelClientId, restHighLevelClient);
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -34,6 +34,10 @@ public class CreateIndexParam {
|
||||
* 副本数
|
||||
*/
|
||||
private Integer replicasNum;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
private Integer maxResultWindow;
|
||||
/**
|
||||
* 索引字段及类型分词器等信息
|
||||
*/
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.annotation.rely.FieldStrategy;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.core.config.GlobalConfig;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import lombok.AccessLevel;
|
||||
@ -36,7 +36,7 @@ public class EntityFieldInfo {
|
||||
*/
|
||||
private String mappingColumn;
|
||||
/**
|
||||
* 自动在es中的存储类型
|
||||
* 自段在es中的存储类型
|
||||
*/
|
||||
private FieldType fieldType;
|
||||
/**
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
import cn.easyes.annotation.rely.JoinField;
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.common.params.JoinField;
|
||||
import com.alibaba.fastjson.PropertyNamingStrategy;
|
||||
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
@ -14,6 +14,8 @@ import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.DEFAULT_MAX_RESULT_WINDOW;
|
||||
|
||||
/**
|
||||
* 实体类信息
|
||||
* <p>
|
||||
@ -42,6 +44,10 @@ public class EntityInfo {
|
||||
* 重试成功的索引名
|
||||
*/
|
||||
private String retrySuccessIndexName;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
private Integer maxResultWindow = DEFAULT_MAX_RESULT_WINDOW;
|
||||
/**
|
||||
* 表映射结果集
|
||||
*/
|
||||
|
||||
@ -26,6 +26,10 @@ public class EsIndexInfo {
|
||||
* 副本数
|
||||
*/
|
||||
private Integer replicasNum;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
private Integer maxResultWindow;
|
||||
/**
|
||||
* 索引字段信息
|
||||
*/
|
||||
|
||||
@ -13,7 +13,7 @@ import java.util.List;
|
||||
**/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class PageInfo<T> extends PageSerializable<T> {
|
||||
public class EsPageInfo<T> extends PageSerializable<T> {
|
||||
/**
|
||||
* 当前页
|
||||
*/
|
||||
@ -72,7 +72,7 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
/**
|
||||
* 所有导航页号
|
||||
*/
|
||||
private int[] navigatepageNums;
|
||||
private int[] navigatePageNums;
|
||||
/**
|
||||
* 导航条上的第一页
|
||||
*/
|
||||
@ -87,7 +87,7 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
*
|
||||
* @param list 数据
|
||||
*/
|
||||
public PageInfo(List<T> list) {
|
||||
public EsPageInfo(List<T> list) {
|
||||
this(list, 8);
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
* @param list 数据
|
||||
* @param navigatePages 导航页
|
||||
*/
|
||||
public PageInfo(List<T> list, int navigatePages) {
|
||||
public EsPageInfo(List<T> list, int navigatePages) {
|
||||
super(list);
|
||||
this.pageNum = 1;
|
||||
this.pageSize = list.size();
|
||||
@ -108,34 +108,28 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
this.endRow = list.size() > 0 ? list.size() - 1 : 0;
|
||||
|
||||
this.navigatePages = navigatePages;
|
||||
//计算导航页
|
||||
calcNavigatepageNums();
|
||||
//计算前后页,第一页,最后一页
|
||||
calcPage();
|
||||
//判断页面边界
|
||||
judgePageBoudary();
|
||||
}
|
||||
|
||||
public static <T> PageInfo<T> of(List<T> list) {
|
||||
return new PageInfo<T>(list);
|
||||
public static <T> EsPageInfo<T> of(List<T> list) {
|
||||
return new EsPageInfo<T>(list);
|
||||
}
|
||||
|
||||
public static <T> PageInfo<T> of(List<T> list, int navigatePages) {
|
||||
return new PageInfo<T>(list, navigatePages);
|
||||
public static <T> EsPageInfo<T> of(List<T> list, int navigatePages) {
|
||||
return new EsPageInfo<T>(list, navigatePages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算导航页
|
||||
*/
|
||||
private void calcNavigatepageNums() {
|
||||
public void calcNavigatePageNums() {
|
||||
//当总页数小于或等于导航页码数时
|
||||
if (pages <= navigatePages) {
|
||||
navigatepageNums = new int[pages];
|
||||
navigatePageNums = new int[pages];
|
||||
for (int i = 0; i < pages; i++) {
|
||||
navigatepageNums[i] = i + 1;
|
||||
navigatePageNums[i] = i + 1;
|
||||
}
|
||||
} else { //当总页数大于导航页码数时
|
||||
navigatepageNums = new int[navigatePages];
|
||||
navigatePageNums = new int[navigatePages];
|
||||
int startNum = pageNum - navigatePages / 2;
|
||||
int endNum = pageNum + navigatePages / 2;
|
||||
|
||||
@ -143,18 +137,18 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
startNum = 1;
|
||||
//(最前navigatePages页
|
||||
for (int i = 0; i < navigatePages; i++) {
|
||||
navigatepageNums[i] = startNum++;
|
||||
navigatePageNums[i] = startNum++;
|
||||
}
|
||||
} else if (endNum > pages) {
|
||||
endNum = pages;
|
||||
//最后navigatePages页
|
||||
for (int i = navigatePages - 1; i >= 0; i--) {
|
||||
navigatepageNums[i] = endNum--;
|
||||
navigatePageNums[i] = endNum--;
|
||||
}
|
||||
} else {
|
||||
//所有中间页
|
||||
for (int i = 0; i < navigatePages; i++) {
|
||||
navigatepageNums[i] = startNum++;
|
||||
navigatePageNums[i] = startNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,10 +157,10 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
/**
|
||||
* 计算前后页,第一页,最后一页
|
||||
*/
|
||||
private void calcPage() {
|
||||
if (navigatepageNums != null && navigatepageNums.length > 0) {
|
||||
navigateFirstPage = navigatepageNums[0];
|
||||
navigateLastPage = navigatepageNums[navigatepageNums.length - 1];
|
||||
public void calcPage() {
|
||||
if (navigatePageNums != null && navigatePageNums.length > 0) {
|
||||
navigateFirstPage = navigatePageNums[0];
|
||||
navigateLastPage = navigatePageNums[navigatePageNums.length - 1];
|
||||
if (pageNum > 1) {
|
||||
prePage = pageNum - 1;
|
||||
}
|
||||
@ -179,10 +173,9 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
/**
|
||||
* 判定页面边界
|
||||
*/
|
||||
private void judgePageBoudary() {
|
||||
public void judgePageBoundary() {
|
||||
isFirstPage = pageNum == 1;
|
||||
isLastPage = pageNum == pages || pages == 0;
|
||||
;
|
||||
hasPreviousPage = pageNum > 1;
|
||||
hasNextPage = pageNum < pages;
|
||||
}
|
||||
@ -203,7 +196,7 @@ public class PageInfo<T> extends PageSerializable<T> {
|
||||
", hasPreviousPage=" + hasPreviousPage +
|
||||
", hasNextPage=" + hasNextPage +
|
||||
", navigatePages=" + navigatePages +
|
||||
", navigatepageNums=" + Arrays.toString(navigatepageNums) +
|
||||
", navigatepageNums=" + Arrays.toString(navigatePageNums) +
|
||||
", navigateFirstPage=" + navigateFirstPage +
|
||||
", navigateLastPage=" + navigateLastPage +
|
||||
", total=" + total +
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.common.enums.HighLightTypeEnum;
|
||||
import cn.easyes.annotation.rely.HighLightTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package cn.easyes.core.conditions;
|
||||
|
||||
import cn.easyes.annotation.rely.FieldStrategy;
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.common.enums.EsQueryTypeEnum;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.common.utils.*;
|
||||
import cn.easyes.core.biz.*;
|
||||
import cn.easyes.core.cache.BaseCache;
|
||||
@ -38,6 +38,7 @@ 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;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
@ -177,7 +178,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<T> pageQuery(LambdaEsQueryWrapper<T> wrapper, Integer pageNum, Integer pageSize) {
|
||||
public EsPageInfo<T> pageQuery(LambdaEsQueryWrapper<T> wrapper, Integer pageNum, Integer pageSize) {
|
||||
// 兼容分页参数
|
||||
pageNum = pageNum == null || pageNum <= BaseEsConstants.ZERO ? BaseEsConstants.PAGE_NUM : pageNum;
|
||||
pageSize = pageSize == null || pageSize <= BaseEsConstants.ZERO ? BaseEsConstants.PAGE_SIZE : pageSize;
|
||||
@ -190,7 +191,8 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
|
||||
// 解析数据
|
||||
SearchHit[] searchHits = parseSearchHitArray(response);
|
||||
List<T> dataList = Arrays.stream(searchHits).map(searchHit -> parseOne(searchHit, wrapper))
|
||||
List<T> dataList = Arrays.stream(searchHits)
|
||||
.map(searchHit -> parseOne(searchHit, wrapper))
|
||||
.collect(Collectors.toList());
|
||||
long count = parseCount(response, Objects.nonNull(wrapper.distinctField));
|
||||
return PageHelper.getPageInfo(dataList, count, pageNum, pageSize);
|
||||
@ -247,9 +249,11 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
} else {
|
||||
// 不去重,直接count获取,效率更高
|
||||
CountRequest countRequest = new CountRequest(getIndexNames(wrapper.indexNames));
|
||||
BoolQueryBuilder boolQueryBuilder = WrapperProcessor.initBoolQueryBuilder(wrapper.baseEsParamList,
|
||||
wrapper.enableMust2Filter, entityClass);
|
||||
countRequest.query(boolQueryBuilder);
|
||||
QueryBuilder queryBuilder = Optional.ofNullable(wrapper.searchSourceBuilder)
|
||||
.map(SearchSourceBuilder::query)
|
||||
.orElseGet(() -> WrapperProcessor.initBoolQueryBuilder(wrapper.baseEsParamList,
|
||||
wrapper.enableMust2Filter, entityClass));
|
||||
countRequest.query(queryBuilder);
|
||||
CountResponse count;
|
||||
try {
|
||||
printCountDSL(countRequest);
|
||||
@ -495,6 +499,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
// 设置分片个副本信息
|
||||
Optional.ofNullable(wrapper.shardsNum).ifPresent(createIndexParam::setShardsNum);
|
||||
Optional.ofNullable(wrapper.replicasNum).ifPresent(createIndexParam::setReplicasNum);
|
||||
Optional.ofNullable(wrapper.maxResultWindow).ifPresent(createIndexParam::setMaxResultWindow);
|
||||
|
||||
// 设置用户自定义的settings
|
||||
Optional.ofNullable(wrapper.settings).ifPresent(createIndexParam::setSettings);
|
||||
@ -760,9 +765,15 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
private SearchResponse getSearchResponse(LambdaEsQueryWrapper<T> wrapper, Object[] searchAfter) {
|
||||
// 构建es restHighLevelClient 查询参数
|
||||
SearchRequest searchRequest = new SearchRequest(getIndexNames(wrapper.indexNames));
|
||||
|
||||
// 用户在wrapper中指定的混合查询条件优先级最高
|
||||
SearchSourceBuilder searchSourceBuilder = Objects.isNull(wrapper.searchSourceBuilder) ?
|
||||
WrapperProcessor.buildSearchSourceBuilder(wrapper, entityClass) : wrapper.searchSourceBuilder;
|
||||
SearchSourceBuilder searchSourceBuilder = Optional.ofNullable(wrapper.searchSourceBuilder)
|
||||
.map(builder -> {
|
||||
// 兼容混合查询时用户在分页中自定义的分页参数
|
||||
Optional.ofNullable(wrapper.from).ifPresent(builder::from);
|
||||
Optional.ofNullable(wrapper.size).ifPresent(builder::size);
|
||||
return builder;
|
||||
}).orElseGet(() -> WrapperProcessor.buildSearchSourceBuilder(wrapper, entityClass));
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
Optional.ofNullable(searchAfter).ifPresent(searchSourceBuilder::searchAfter);
|
||||
printDSL(searchRequest);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.easyes.core.conditions;
|
||||
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.common.params.SFunction;
|
||||
import cn.easyes.common.utils.ArrayUtils;
|
||||
import cn.easyes.common.utils.StringUtils;
|
||||
@ -9,10 +10,7 @@ import cn.easyes.core.conditions.interfaces.Index;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 索引Lambda表达式
|
||||
@ -33,6 +31,10 @@ public class LambdaEsIndexWrapper<T> extends Wrapper<T> implements Index<LambdaE
|
||||
* 副本数
|
||||
*/
|
||||
protected Integer replicasNum;
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
protected Integer maxResultWindow;
|
||||
/**
|
||||
* 用户手动指定的索引mapping信息,优先级最高
|
||||
*/
|
||||
@ -82,6 +84,11 @@ public class LambdaEsIndexWrapper<T> extends Wrapper<T> implements Index<LambdaE
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaEsIndexWrapper<T> maxResultWindow(Integer maxResultWindow) {
|
||||
Optional.ofNullable(maxResultWindow).ifPresent(max -> this.maxResultWindow = maxResultWindow);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaEsIndexWrapper<T> settings(Integer shards, Integer replicas) {
|
||||
|
||||
@ -28,7 +28,7 @@ public class LambdaEsUpdateWrapper<T> extends AbstractLambdaUpdateWrapper<T, Lam
|
||||
protected SearchSourceBuilder searchSourceBuilder;
|
||||
|
||||
/**
|
||||
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
||||
* 不建议直接 new 该实例,使用 EsWrappers.lambdaQuery(entity)
|
||||
*/
|
||||
public LambdaEsUpdateWrapper() {
|
||||
this(null);
|
||||
|
||||
@ -222,14 +222,11 @@ public class WrapperProcessor {
|
||||
Optional.ofNullable(wrapper.from).ifPresent(searchSourceBuilder::from);
|
||||
MyOptional.ofNullable(wrapper.size).ifPresent(searchSourceBuilder::size, DEFAULT_SIZE);
|
||||
|
||||
if (searchSourceBuilder.size() > DEFAULT_SIZE) {
|
||||
// 查询超过一万条, trackTotalHists自动开启
|
||||
searchSourceBuilder.trackTotalHits(true);
|
||||
} else {
|
||||
// 根据全局配置决定是否开启
|
||||
searchSourceBuilder.trackTotalHits(GlobalConfigCache.getGlobalConfig().getDbConfig().isEnableTrackTotalHits());
|
||||
// 根据全局配置决定是否开启
|
||||
if (GlobalConfigCache.getGlobalConfig().getDbConfig().isEnableTrackTotalHits()) {
|
||||
searchSourceBuilder.trackTotalHits(Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
return searchSourceBuilder;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.core.conditions.interfaces;
|
||||
|
||||
import cn.easyes.core.biz.PageInfo;
|
||||
import cn.easyes.core.biz.EsPageInfo;
|
||||
import cn.easyes.core.biz.SAPageInfo;
|
||||
import cn.easyes.core.conditions.LambdaEsIndexWrapper;
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
@ -137,7 +137,7 @@ public interface BaseEsMapper<T> {
|
||||
* @param pageSize 每页条数
|
||||
* @return 指定的返回类型
|
||||
*/
|
||||
PageInfo<T> pageQuery(LambdaEsQueryWrapper<T> wrapper, Integer pageNum, Integer pageSize);
|
||||
EsPageInfo<T> pageQuery(LambdaEsQueryWrapper<T> wrapper, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* searchAfter类型分页
|
||||
|
||||
@ -536,7 +536,7 @@ public interface Func<Children, R> extends Serializable {
|
||||
}
|
||||
|
||||
default Children avg(boolean enablePipeline, String column) {
|
||||
return avg(true, enablePipeline, column, column);
|
||||
return avg(true, enablePipeline, column);
|
||||
}
|
||||
|
||||
default Children avg(String... columns) {
|
||||
@ -570,8 +570,8 @@ public interface Func<Children, R> extends Serializable {
|
||||
return min(true, enablePipeline, column);
|
||||
}
|
||||
|
||||
default Children min(R... column) {
|
||||
return min(true, true, column);
|
||||
default Children min(R... columns) {
|
||||
return min(true, true, columns);
|
||||
}
|
||||
|
||||
default Children min(boolean enablePipeline, R... columns) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.core.conditions.interfaces;
|
||||
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.core.toolkit.FieldUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
@ -21,6 +21,14 @@ public interface Index<Children, R> extends Serializable {
|
||||
*/
|
||||
Children indexName(String... indexNames);
|
||||
|
||||
/**
|
||||
* 设置最大返回数
|
||||
*
|
||||
* @param maxResultWindow 最大返回数
|
||||
* @return 泛型
|
||||
*/
|
||||
Children maxResultWindow(Integer maxResultWindow);
|
||||
|
||||
/**
|
||||
* 设置索引的分片数和副本数
|
||||
*
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
package cn.easyes.core.config;
|
||||
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
|
||||
import cn.easyes.annotation.rely.FieldStrategy;
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.enums.RefreshPolicy;
|
||||
import lombok.Data;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package cn.easyes.core.toolkit;
|
||||
|
||||
import cn.easyes.annotation.*;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.common.params.DefaultNestedClass;
|
||||
import cn.easyes.annotation.rely.DefaultNestedClass;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
import cn.easyes.common.utils.ClassUtils;
|
||||
import cn.easyes.common.utils.FastJsonUtils;
|
||||
import cn.easyes.common.utils.ReflectionKit;
|
||||
@ -589,6 +589,7 @@ public class EntityInfoHelper {
|
||||
} else {
|
||||
indexName = tableName;
|
||||
}
|
||||
entityInfo.setMaxResultWindow(table.maxResultWindow());
|
||||
entityInfo.setAliasName(table.aliasName());
|
||||
entityInfo.setShardsNum(table.shardsNum());
|
||||
entityInfo.setReplicasNum(table.replicasNum());
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package cn.easyes.core.toolkit;
|
||||
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
|
||||
import cn.easyes.annotation.rely.Analyzer;
|
||||
import cn.easyes.annotation.rely.DefaultChildClass;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.enums.JdkDataTypeEnum;
|
||||
import cn.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||
import cn.easyes.common.params.DefaultChildClass;
|
||||
import cn.easyes.common.utils.*;
|
||||
import cn.easyes.core.biz.*;
|
||||
import cn.easyes.core.cache.GlobalConfigCache;
|
||||
@ -45,6 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static cn.easyes.annotation.rely.AnnotationConstants.DEFAULT_ALIAS;
|
||||
import static cn.easyes.common.constants.BaseEsConstants.*;
|
||||
|
||||
|
||||
@ -106,6 +108,9 @@ public class IndexUtils {
|
||||
Settings.Builder settings = Settings.builder();
|
||||
Optional.ofNullable(indexParam.getShardsNum()).ifPresent(shards -> settings.put(BaseEsConstants.SHARDS_FIELD, shards));
|
||||
Optional.ofNullable(indexParam.getReplicasNum()).ifPresent(replicas -> settings.put(BaseEsConstants.REPLICAS_FIELD, replicas));
|
||||
|
||||
// 最大返回个数
|
||||
Optional.ofNullable(indexParam.getMaxResultWindow()).ifPresent(maxResultWindow -> settings.put(MAX_RESULT_WINDOW_FIELD, maxResultWindow));
|
||||
createIndexRequest.settings(settings);
|
||||
} else {
|
||||
// 用户自定义settings
|
||||
@ -190,18 +195,31 @@ public class IndexUtils {
|
||||
* @param indexName 索引名
|
||||
*/
|
||||
public static void addDefaultAlias(RestHighLevelClient client, String indexName) {
|
||||
addAliases(client, indexName, DEFAULT_ALIAS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加别名
|
||||
*
|
||||
* @param client RestHighLevelClient
|
||||
* @param indexName 索引名
|
||||
* @param aliases 别名数组,可以是单个
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
public static Boolean addAliases(RestHighLevelClient client, String indexName, String... aliases) {
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
IndicesAliasesRequest.AliasActions aliasActions =
|
||||
new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD);
|
||||
aliasActions.index(indexName);
|
||||
aliasActions.alias(BaseEsConstants.DEFAULT_ALIAS);
|
||||
aliasActions.aliases(aliases);
|
||||
indicesAliasesRequest.addAliasAction(aliasActions);
|
||||
try {
|
||||
client.indices().updateAliases(indicesAliasesRequest, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
LogUtils.warn("addDefaultAlias exception", e.toString());
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,12 +266,12 @@ public class IndexUtils {
|
||||
.flatMap(aliases -> Optional.ofNullable(aliases.get(indexName)))
|
||||
.ifPresent(aliasMetadataList ->
|
||||
aliasMetadataList.forEach(aliasMetadata -> {
|
||||
if (BaseEsConstants.DEFAULT_ALIAS.equals(aliasMetadata.alias())) {
|
||||
if (DEFAULT_ALIAS.equals(aliasMetadata.alias())) {
|
||||
esIndexInfo.setHasDefaultAlias(Boolean.TRUE);
|
||||
}
|
||||
}));
|
||||
|
||||
// 设置分片及副本数
|
||||
// 设置分片、副本、最大返回数等
|
||||
Optional.ofNullable(getIndexResponse.getSettings())
|
||||
.flatMap(settingsMap -> Optional.ofNullable(settingsMap.get(indexName)))
|
||||
.ifPresent(p -> {
|
||||
@ -263,6 +281,9 @@ public class IndexUtils {
|
||||
String replicasNumStr = p.get(BaseEsConstants.REPLICAS_NUM_KEY);
|
||||
Optional.ofNullable(replicasNumStr)
|
||||
.ifPresent(r -> esIndexInfo.setReplicasNum(Integer.parseInt(r)));
|
||||
String maxResultWindowStr = p.get(MAX_RESULT_WINDOW_FIELD);
|
||||
Optional.ofNullable(maxResultWindowStr)
|
||||
.ifPresent(m -> esIndexInfo.setMaxResultWindow(Integer.parseInt(maxResultWindowStr)));
|
||||
});
|
||||
|
||||
// 设置mapping信息
|
||||
@ -341,7 +362,7 @@ public class IndexUtils {
|
||||
* @return 索引mapping
|
||||
*/
|
||||
public static Map<String, Object> initMapping(EntityInfo entityInfo, List<EsIndexParam> indexParamList) {
|
||||
Map<String, Object> mapping = new HashMap<>(1);
|
||||
Map<String, Object> mapping = new HashMap<>(2);
|
||||
if (CollectionUtils.isEmpty(indexParamList)) {
|
||||
return mapping;
|
||||
}
|
||||
@ -434,9 +455,9 @@ public class IndexUtils {
|
||||
*/
|
||||
public static boolean changeAliasAtomic(RestHighLevelClient client, String oldIndexName, String releaseIndexName) {
|
||||
IndicesAliasesRequest.AliasActions addIndexAction = new IndicesAliasesRequest.AliasActions(
|
||||
IndicesAliasesRequest.AliasActions.Type.ADD).index(releaseIndexName).alias(BaseEsConstants.DEFAULT_ALIAS);
|
||||
IndicesAliasesRequest.AliasActions.Type.ADD).index(releaseIndexName).alias(DEFAULT_ALIAS);
|
||||
IndicesAliasesRequest.AliasActions removeAction = new IndicesAliasesRequest.AliasActions(
|
||||
IndicesAliasesRequest.AliasActions.Type.REMOVE).index(oldIndexName).alias(BaseEsConstants.DEFAULT_ALIAS);
|
||||
IndicesAliasesRequest.AliasActions.Type.REMOVE).index(oldIndexName).alias(DEFAULT_ALIAS);
|
||||
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
indicesAliasesRequest.addAliasAction(addIndexAction);
|
||||
@ -485,6 +506,7 @@ public class IndexUtils {
|
||||
createIndexParam.setShardsNum(entityInfo.getShardsNum());
|
||||
createIndexParam.setReplicasNum(entityInfo.getReplicasNum());
|
||||
createIndexParam.setIndexName(entityInfo.getIndexName());
|
||||
createIndexParam.setMaxResultWindow(entityInfo.getMaxResultWindow());
|
||||
|
||||
// 如果有设置新索引名称,则用新索引名覆盖原索引名进行创建
|
||||
Optional.ofNullable(entityInfo.getReleaseIndexName()).ifPresent(createIndexParam::setIndexName);
|
||||
@ -565,6 +587,9 @@ public class IndexUtils {
|
||||
if (!entityInfo.getReplicasNum().equals(esIndexInfo.getReplicasNum())) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if (!entityInfo.getMaxResultWindow().equals(esIndexInfo.getMaxResultWindow())) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
// 根据当前实体类及自定义注解配置, 生成最新的Mapping信息
|
||||
List<EsIndexParam> esIndexParamList = IndexUtils.initIndexParam(entityInfo, entityInfo.getFieldList(), false);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.core.toolkit;
|
||||
|
||||
import cn.easyes.core.biz.PageInfo;
|
||||
import cn.easyes.core.biz.EsPageInfo;
|
||||
import cn.easyes.core.biz.SAPageInfo;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -24,12 +24,18 @@ public class PageHelper {
|
||||
* @param <T> 数据类型
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <T> PageInfo<T> getPageInfo(List<T> list, Long total, Integer pageNum, Integer pageSize) {
|
||||
PageInfo<T> pageInfo = new PageInfo<>(list);
|
||||
public static <T> EsPageInfo<T> getPageInfo(List<T> list, Long total, Integer pageNum, Integer pageSize) {
|
||||
EsPageInfo<T> pageInfo = new EsPageInfo<>(list);
|
||||
pageInfo.setTotal(total);
|
||||
pageInfo.setPageNum(pageNum);
|
||||
pageInfo.setPageSize(pageSize);
|
||||
pageInfo.setPages((int) (total % pageSize > 0 ? total / pageSize + 1 : total / pageSize));
|
||||
// 计算导航页
|
||||
pageInfo.calcNavigatePageNums();
|
||||
// 计算前后页,第一页,最后一页
|
||||
pageInfo.calcPage();
|
||||
// 判断页面边界
|
||||
pageInfo.judgePageBoundary();
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -23,6 +23,10 @@
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-annotation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
|
||||
<name>easy-es-parent</name>
|
||||
<description>easy use for elastic search</description>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<artifactId>easy-es</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@ -21,6 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-boot-starter</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -12,7 +12,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
/**l
|
||||
* 演示springboot项目实际使用
|
||||
* <p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
|
||||
@ -4,10 +4,10 @@ import cn.easyes.annotation.HighLight;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexId;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.annotation.rely.Analyzer;
|
||||
import cn.easyes.annotation.rely.FieldStrategy;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.annotation.rely.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ -18,7 +18,7 @@ import lombok.experimental.Accessors;
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@IndexName(value = "easyes_document", shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true)
|
||||
@IndexName(value = "easyes_document", shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true,maxResultWindow = 100)
|
||||
public class Document {
|
||||
/**
|
||||
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
||||
|
||||
@ -5,15 +5,37 @@ easy-es:
|
||||
username: elastic
|
||||
password: WG7WVmuNMtM4GwNYkyWH
|
||||
keep-alive-millis: 18000
|
||||
# address: 10.20.64.228:9200
|
||||
# schema: http
|
||||
# username: elastic
|
||||
# password: WG7WVmuNMtM4GwNYkyWH
|
||||
# keep-alive-millis: 18000
|
||||
global-config:
|
||||
process-index-mode: smoothly
|
||||
async-process-index-blocking: true
|
||||
print-dsl: false
|
||||
db-config:
|
||||
map-underscore-to-camel-case: true
|
||||
# table-prefix: dev_
|
||||
id-type: customize
|
||||
field-strategy: not_empty
|
||||
refresh-policy: immediate
|
||||
enable-track-total-hits: true
|
||||
enable-must2-filter: false
|
||||
process-index-mode: manual
|
||||
distributed: false
|
||||
# async-process-index-blocking: true
|
||||
# print-dsl: false
|
||||
# db-config:
|
||||
# map-underscore-to-camel-case: true
|
||||
# # table-prefix: dev_
|
||||
# id-type: customize
|
||||
# field-strategy: not_empty
|
||||
# refresh-policy: immediate
|
||||
# enable-track-total-hits: true
|
||||
# enable-must2-filter: false
|
||||
dynamic:
|
||||
datasource:
|
||||
db1:
|
||||
address: #填你的es连接地址
|
||||
username: 'username1'
|
||||
password: 'pwd'
|
||||
db2:
|
||||
address: #填你的es连接地址
|
||||
username: 'username2'
|
||||
password: 'pwd2'
|
||||
|
||||
|
||||
management:
|
||||
health:
|
||||
elasticsearch:
|
||||
enabled: false
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<artifactId>easy-es</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>easy-es-test</artifactId>
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.params.JoinField;
|
||||
import cn.easyes.annotation.rely.Analyzer;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.annotation.rely.JoinField;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* es 评论 数据模型 Document的子文档,Document是其父文档
|
||||
* <p>
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.*;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.enums.HighLightTypeEnum;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.common.params.JoinField;
|
||||
import cn.easyes.annotation.rely.*;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -26,7 +26,7 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Faq {
|
||||
@IndexField(value = "faq_name",fieldType = FieldType.TEXT)
|
||||
@IndexField(value = "faq_name", fieldType = FieldType.TEXT)
|
||||
private String faqName;
|
||||
private String faqAnswer;
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
|
||||
import cn.easyes.annotation.rely.Analyzer;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.test.agg;
|
||||
|
||||
import cn.easyes.core.biz.PageInfo;
|
||||
import cn.easyes.core.biz.EsPageInfo;
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
import cn.easyes.test.TestEasyEsApplication;
|
||||
import cn.easyes.test.entity.Document;
|
||||
@ -29,7 +29,7 @@ public class AggTest {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getTitle, "老汉")
|
||||
.distinct(Document::getSubTitle);
|
||||
PageInfo<Document> pageInfo = documentMapper.pageQuery(wrapper, 1, 10);
|
||||
EsPageInfo<Document> pageInfo = documentMapper.pageQuery(wrapper, 1, 10);
|
||||
System.out.println(pageInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package cn.easyes.test.all;
|
||||
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.core.biz.EsPageInfo;
|
||||
import cn.easyes.core.biz.OrderByParam;
|
||||
import cn.easyes.core.biz.PageInfo;
|
||||
import cn.easyes.core.biz.SAPageInfo;
|
||||
import cn.easyes.core.cache.GlobalConfigCache;
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
@ -526,7 +526,7 @@ public class AllTest {
|
||||
public void testPageQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
PageInfo<Document> pageInfo = documentMapper.pageQuery(wrapper, 1, 5);
|
||||
EsPageInfo<Document> pageInfo = documentMapper.pageQuery(wrapper, 1, 5);
|
||||
Assertions.assertEquals(5, pageInfo.getSize());
|
||||
Assertions.assertEquals(22, pageInfo.getTotal());
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cn.easyes.test.high;
|
||||
|
||||
import cn.easyes.core.biz.EsPageInfo;
|
||||
import cn.easyes.core.biz.OrderByParam;
|
||||
import cn.easyes.core.biz.PageInfo;
|
||||
import cn.easyes.core.biz.SAPageInfo;
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
import cn.easyes.core.toolkit.EsWrappers;
|
||||
@ -122,7 +122,7 @@ public class HighTest {
|
||||
// 浅分页,适合数据量少于1w的情况
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getTitle, "老汉");
|
||||
PageInfo<Document> documentPageInfo = documentMapper.pageQuery(wrapper, 1, 10);
|
||||
EsPageInfo<Document> documentPageInfo = documentMapper.pageQuery(wrapper, 2, 10);
|
||||
System.out.println(documentPageInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
package cn.easyes.test.index;
|
||||
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
|
||||
import cn.easyes.annotation.rely.Analyzer;
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.core.conditions.LambdaEsIndexWrapper;
|
||||
import cn.easyes.test.TestEasyEsApplication;
|
||||
import cn.easyes.test.entity.Document;
|
||||
import cn.easyes.test.mapper.DocumentMapper;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.elasticsearch.client.indices.GetIndexResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.test.join;
|
||||
|
||||
import cn.easyes.common.params.JoinField;
|
||||
import cn.easyes.annotation.rely.JoinField;
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
import cn.easyes.core.conditions.LambdaEsUpdateWrapper;
|
||||
import cn.easyes.core.toolkit.FieldUtils;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cn.easyes.test.other;
|
||||
|
||||
import cn.easyes.annotation.rely.FieldType;
|
||||
import cn.easyes.common.constants.BaseEsConstants;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.core.conditions.LambdaEsIndexWrapper;
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
import cn.easyes.core.toolkit.EntityInfoHelper;
|
||||
|
||||
5
pom.xml
5
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.1.1</version>
|
||||
|
||||
<name>easy-es</name>
|
||||
<description>easy use for elastic search</description>
|
||||
@ -19,7 +19,8 @@
|
||||
|
||||
<properties>
|
||||
<junit.version>5.4.0</junit.version>
|
||||
<spring-boot.version>2.6.10</spring-boot.version>
|
||||
<!-- <spring-boot.version>2.6.10</spring-boot.version>-->
|
||||
<spring-boot.version>2.7.0</spring-boot.version>
|
||||
<commons-lang3>3.9</commons-lang3>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user