# easy-es
**Repository Path**: wonray/easy-es
## Basic Information
- **Project Name**: easy-es
- **Description**: 更好用的elastic search搜索引擎框架,与Mybatis-plus一致的API,屏蔽语言差异,开发者只需要会MySQL语法即可完成对Es的相关操作,零额外学习成本.底层采用RestHighLevelClient,兼具低码,易用,易拓展等特性,支持es独有的高亮,权重,分词,Geo等功能...
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: https://easy-es.cn
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1800
- **Created**: 2022-04-08
- **Last Updated**: 2022-04-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Born To Simplify Development
## 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
---
https://easy-es.cn/#/en/
## Links
---
- [中文版](https://github.com/xpc1024/easy-es/blob/main/README-ZH.md)
- [Documentation](https://www.yuque.com/laohan-14b9d/tald79/qf7ns2)
- [Samples](https://github.com/xpc1024/easy-es/tree/main/easy-es-sample)
- [Demo in Springboot](https://github.com/xpc1024/easy-es-springboot-demo-en)
## Features
---
- 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
- ...
## 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 wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Hi").eq(Document::getCreator, "Guy");
List 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
---
- Add Easy-Es dependency
- Latest Version: [](https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*)
- Maven:
```xml
io.github.xpc1024
easy-es-boot-starter
Latest Version
```
- Gradle
```groovy
compile group: 'io.github.xpc1024', name: 'easy-es-boot-starter', version: 'Latest Version'
```
- Add mapper file extends BaseEsMapper interface
```java
public interface DocumentMapper extends BaseMapper {
}
```
- Use it
``` java
LambdaEsQueryWrapper wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle,"Hello World")
.eq(Document::getCreator,"Guy");
List 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://www.yuque.com/laohan-14b9d/tald79/qf7ns2).
## Syntax comparison with MySQL
---
| 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 |
| ... | ... |
---
## Donate
---
[Donate Easy-Es](https://www.yuque.com/laohan-14b9d/tald79/oqpgto)
## 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.