Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature #106 interface支持default方法 #107

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

**easy-es官网** https://easy-es.cn/

**easy-es备用官网** http://47.92.157.199 (国内用户如偶遇官网打不开,可访"无言"先生捐赠的此备用地址)

**easy-es官方gitee** https://gitee.com/dromara/easy-es

**easy-es官方github** https://github.com/dromara/easy-es
Expand Down Expand Up @@ -55,7 +57,7 @@ Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动
- **全自动索引托管:** 全球开源首创的索引托管模式,开发者无需关心索引的创建更新及数据迁移等繁琐步骤,索引全生命周期皆可托管给框架,由框架自动完成,过程零停机,用户无感知,彻底解放开发者
- **智能字段类型推断:** 根据索引类型和当前查询类型上下文综合智能判断当前查询是否需要拼接.keyword后缀,减少小白误用的可能
- **屏蔽语言差异:** 开发者只需要会MySQL语法即可使用Es
- **代码量极少:** 与直接使用RestHighLevelClient相比,相同的查询平均可以节3-8倍左右的代码量
- **代码量极少:** 与直接使用RestHighLevelClient相比,相同的查询平均可以节3-80倍左右的代码量
- **零魔法值:** 字段名称直接从实体中获取,无需输入字段名称字符串这种魔法值
- **零额外学习成本:** 开发者只要会国内最受欢迎的Mybatis-Plus语法,即可无缝迁移至Easy-Es
- **降低开发者门槛:** 即便是只了解ES基础的初学者也可以轻松驾驭ES完成绝大多数需求的开发
Expand Down Expand Up @@ -97,7 +99,7 @@ Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动
e.printStackTrace();
}
```
> * 以上只是简单查询演示,实际使用场景越复杂,效果就越好,平均可节省至少3-8倍代码量
> * 以上只是简单查询演示,实际使用场景越复杂,效果就越好,平均可节省至少3-80倍代码量
> * 传统功夫,点到为止! 上述功能仅供演示,仅为Easy-Es支持功能的冰山一角,Easy-Es就是这么Easy到不讲武德💪,不用的请耗子尾汁.

# 架构 | Architecture
Expand Down Expand Up @@ -171,14 +173,20 @@ QQ | 微信:252645816

> 我们的广告投放商,如果您期望Easy-Es能够走得更远,不妨点击下图,支持一下我们的广告商Thanks♪(・ω・)ノ

<a href="https://www.mingdao.com?s=utm_70&utm_source=easy-es&utm_medium=banner&utm_campaign=gitee&utm_content=IT%E8%B5%8B%E8%83%BD%E4%B8%9A%E5%8A%A1">
<img alt="ad" src="https://iknow.hs.net/26a6e238-8b23-463c-8cf9-f62cc3f52e0f.png">
</a>

</br>

<a href="https://www.misboot.com/?from=easy-es">
<img alt="ad" src="https://iknow.hs.net/68963214-7a61-4f38-b5b5-a068c07a35f1.png">
</a>

</br>

<a href="https://www.mingdao.com?s=utm_70&utm_source=easy-es&utm_medium=banner&utm_campaign=gitee&utm_content=IT%E8%B5%8B%E8%83%BD%E4%B8%9A%E5%8A%A1">
<img alt="ad" src="https://iknow.hs.net/26a6e238-8b23-463c-8cf9-f62cc3f52e0f.png">
<a href="http://www.yunchengxc.com/">
<img alt="ad" src="https://iknow.hs.net/ea88661b-3d02-4dba-aacb-8907a4ca8f11.jpg">
</a>


Expand Down
208 changes: 17 additions & 191 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ Easy-Es is a powerfully enhanced toolkit of RestHighLevelClient for simplify dev


```java

// Use Easy-Es to complete the query with only 1 lines of code
List<Document> documents = documentMapper.selectList(EsWrappers.lambdaQuery(Document.class).eq(Document::getTitle, "Hi").eq(Document::getCreator, "Guy"));
// Use Easy-Es to complete the query with only 3 lines of code
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Hi").eq(Document::getCreator, "Guy");
List<Document> documents = documentMapper.selectList(wrapper);
```

```java
Expand All @@ -83,13 +84,11 @@ String indexName = "document";
}
```

> The above is just a simple query demonstration. The more complex the actual query scene, the better the effect, which can save 3-5 times the amount of code on average.
> The above is just a simple query demonstration. The more complex the actual query scene, the better the effect, which can save 3-80 times the amount of code on average.
## Getting started

- Latest Version: [![Maven Central](https://img.shields.io/github/v/release/xpc1024/easy-es?include_prereleases&logo=xpc&style=plastic)](https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*)

- Add Easy-Es dependency

- Add Easy-Es dependency
- Latest Version: [![Maven Central](https://img.shields.io/github/v/release/xpc1024/easy-es?include_prereleases&logo=xpc&style=plastic)](https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*)
- Maven:
```xml
<dependency>
Expand Down Expand Up @@ -135,7 +134,6 @@ String indexName = "document";

## MySQL Easy-Es and Es syntax comparison table


| MySQL | Easy-Es | Es-DSL/Es java api|
| --- | --- |--- |
| and | and |must|
Expand Down Expand Up @@ -171,200 +169,28 @@ String indexName = "document";
| select * | matchAllQuery |QueryBuilders.matchAllQuery()|
| - | highLight |HighlightBuilder.Field |
| ... | ... | ...|
---

## Advertising provider
<a href="https://www.mingdao.com?s=utm_69&utm_source=easy-es&utm_medium=banner&utm_campaign=github&utm_content=IT%E8%B5%8B%E8%83%BD%E4%B8%9A%E5%8A%A1

<a href="https://www.mingdao.com?s=utm_70&utm_source=easy-es&utm_medium=banner&utm_campaign=gitee&utm_content=IT%E8%B5%8B%E8%83%BD%E4%B8%9A%E5%8A%A1
">
<img alt="ad" src="https://iknow.hs.net/26a6e238-8b23-463c-8cf9-f62cc3f52e0f.png">
</a>

## Donate

[Donate Easy-Es](https://en.easy-es.cn/pages/fb291d/)


## License

Easy-Es is under the Apache 2.0 license. See the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) file for details.
<p align="center">
<a href="https://en.easy-es.cn/">
<img alt="East-Es-Logo" src="https://iknow.hs.net/042dd639-5bfa-410f-968f-8bbceb8d8ca7.png">
</a>
</p>

<p align="center">
Born To Simplify Development
</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/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>
</p>

## What is Easy-Es?

Easy-Es is a powerfully enhanced toolkit of RestHighLevelClient for simplify development. This toolkit provides some efficient, useful, out-of-the-box features for ElasticSearch. By using Easy-Es, you can use MySQL syntax to complete Es queries. Use it can effectively save your development time.

## Official website

**easy-es website** https://en.easy-es.cn/

**easy-es gitee** https://gitee.com/dromara/easy-es

**easy-es github** https://github.com/dromara/easy-es

**dromara website** https://dromara.org/

**dromara gitee homepage** https://gitee.com/dromara/

## Links

- [中文版](https://github.com/xpc1024/easy-es/blob/main/README-ZH.md)
- [Samples](https://github.com/xpc1024/easy-es/tree/main/easy-es-sample)
- [Demo in Springboot](https://en.easy-es.cn/pages/658abb/#_2-pom)

## Features

- Automatically create and update indexes, automatically migrate data, and process zero downtime
- Auto configuration on startup
- Out-of-the-box interfaces for operate es
- Powerful and flexible where condition wrapper
- Lambda-style API
- Automatic paging operation
- Support high-level syntax such as highlighting and weighting and Geo etc
- ...
</br>

## Compare

> Demand: Query all documents with title equals "Hi" and author equals "Guy"



```java
// Use Easy-Es to complete the query with only 3 lines of code
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Hi").eq(Document::getCreator, "Guy");
List<Document> documents = documentMapper.selectList(wrapper);
```

```java
// Query with RestHighLevelClient requires 11 lines of code, not including parsing JSON code
String indexName = "document";
SearchRequest searchRequest = new SearchRequest(indexName);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
TermQueryBuilder titleTerm = QueryBuilders.termQuery("title", "Hi");
TermsQueryBuilder creatorTerm = QueryBuilders.termsQuery("creator", "Guy");
boolQueryBuilder.must(titleTerm);
boolQueryBuilder.must(creatorTerm);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
// Then parse the DocumentList from searchResponse in various ways, omitting these codes...
} catch (IOException e) {
e.printStackTrace();
}
```

> The above is just a simple query demonstration. The more complex the actual query scene, the better the effect, which can save 3-5 times the amount of code on average.
## Getting started

- Latest Version: [![Maven Central](https://img.shields.io/github/v/release/xpc1024/easy-es?include_prereleases&logo=xpc&style=plastic)](https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*)

- Add Easy-Es dependency

- Maven:
```xml
<dependency>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-boot-starter</artifactId>
<version>Latest Version</version>
</dependency>
```
- Gradle
```groovy
compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: 'Latest Version'
```
- Add mapper file extends BaseEsMapper interface

```java
public interface DocumentMapper extends BaseMapper<User> {
}
```

- Use it
``` java
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle,"Hello World")
.eq(Document::getCreator,"Guy");
List<Document> documentList = documentMapper.selectList();

```
Easy-Es will execute the following Query:
```json
{"query":{"bool":{"must":[{"term":{"title":{"value":"Hello World","boost":1.0}}},{"term":{"creator":{"value":"Guy","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}}
```

The syntax of this query in MySQL is:
```sql
SELECT * FROM document WHERE title = 'Hello World' AND creator = 'Guy'
```

> This showcase is just a small part of Easy-Es features. If you want to learn more, please refer to the [documentation](https://easy-es.cn/#/en/).

## Architecture

![Architecture](https://iknow.hs.net/27fb40b8-22d4-45c2-92e0-1471112d5102.jpg)
<a href="https://www.misboot.com/?from=easy-es">
<img alt="ad" src="https://iknow.hs.net/68963214-7a61-4f38-b5b5-a068c07a35f1.png">
</a>

## MySQL Easy-Es and Es syntax comparison table

</br>

| 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 |
| ... | ... | ...|

## Advertising provider
<a href="https://www.mingdao.com?s=utm_69&utm_source=easy-es&utm_medium=banner&utm_campaign=github&utm_content=IT%E8%B5%8B%E8%83%BD%E4%B8%9A%E5%8A%A1
">
<img alt="ad" src="https://iknow.hs.net/26a6e238-8b23-463c-8cf9-f62cc3f52e0f.png">
<a href="http://www.yunchengxc.com/">
<img alt="ad" src="https://iknow.hs.net/ea88661b-3d02-4dba-aacb-8907a4ca8f11.jpg">
</a>

## Donate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
* 代理类
Expand Down Expand Up @@ -56,7 +57,7 @@ public MapperFactoryBean(Class<T> mapperInterface) {
@Override
public T getObject() throws Exception {

EsMapperProxy<T> esMapperProxy = new EsMapperProxy<>(mapperInterface);
EsMapperProxy<T> esMapperProxy = new EsMapperProxy<>(mapperInterface, new ConcurrentHashMap<>());

// 获取实体类
Class<?> entityClass = TypeUtils.getInterfaceT(mapperInterface, 0);
Expand Down
Loading