From 29ebc56632c4091835a1358db6cb153b244f3b94 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:46:12 +0800 Subject: [PATCH 01/17] Update README.md --- README.md | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/README.md b/README.md index 6a66338..167d65a 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,210 @@ String indexName = "document"; | ... | ... | ...| ## Advertising provider +

+ + East-Es-Logo + +

+ +

+ 您的Star是我继续前进的动力,如果喜欢EE请右上角帮忙点亮星星⭐! +

+ +

+ + maven + + + + code style + +

+ +# 官方地址 | Official website + +**easy-es官网** https://easy-es.cn/ + +**easy-es官方gitee** https://gitee.com/dromara/easy-es + +**easy-es官方github** https://github.com/dromara/easy-es + +**开源社区dromara** https://dromara.org/ + +**开源社区码云首页** https://gitee.com/dromara/ + +> **Tip:** 官网是vue单页面应用,首次访问加载可能比较慢🐢,主公们请耐心等待一下,后续会很快🏹,如偶遇打不开可刷新多尝试几次. + +# 简介 | Intro + +Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动智能索引托管. + +目前功能丰富度和易用度及性能已全面领先SpringData-Elasticsearch. + +简化`CRUD`及其它高阶操作,可以更好的帮助开发者减轻开发负担 + +底层采用Es官方提供的RestHighLevelClient,保证其原生性能及拓展性. + +技术讨论 QQ 群 :729148550 群内可在群文件中免费领取 颈椎保护 | 增肌 | 减脂 等健身计划 无套路 + +微信群请先添加作者微信,由作者拉入 (亦可咨询健身问题,作者是健身教练) + +项目推广初期,还望大家能够不吝点点三连:⭐Star,👀Watch,fork📌 + +支持一下国产开源,让更多人看到和使用本项目,非常感谢! + +# 优点 | Advantages + +- **全自动索引托管:** 全球开源首创的索引托管模式,开发者无需关心索引的创建更新及数据迁移等繁琐步骤,索引全生命周期皆可托管给框架,由框架自动完成,过程零停机,用户无感知,彻底解放开发者 +- **智能字段类型推断:** 根据索引类型和当前查询类型上下文综合智能判断当前查询是否需要拼接.keyword后缀,减少小白误用的可能 +- **屏蔽语言差异:** 开发者只需要会MySQL语法即可使用Es +- **代码量极少:** 与直接使用RestHighLevelClient相比,相同的查询平均可以节3-8倍左右的代码量 +- **零魔法值:** 字段名称直接从实体中获取,无需输入字段名称字符串这种魔法值 +- **零额外学习成本:** 开发者只要会国内最受欢迎的Mybatis-Plus语法,即可无缝迁移至Easy-Es +- **降低开发者门槛:** 即便是只了解ES基础的初学者也可以轻松驾驭ES完成绝大多数需求的开发 +- **功能强大:** 支持MySQL的几乎全部功能,且对ES特有的分词,权重,高亮,嵌套,地理位置Geo,Ip地址查询等功能都支持 +- **语法优雅:** 所有条件构造器均支持Lambda风格链式编程,编程体验和代码可读性大幅提升 +- **安全可靠:** 墨菲安全扫描零风险,且代码单元测试综合覆盖率高达95%以上. +- **完善的中英文文档:** 提供了中英文双语操作文档,文档全面可靠,帮助您节省更多时间 +- **...** + +# 对比 | Compare + +> 需求:查询出文档标题为 "传统功夫"且作者为"码保国"的所有文档 +```java + // 使用Easy-Es仅需1行代码即可完成查询 + List documents = documentMapper.selectList(EsWrappers.lambdaQuery(Document.class).eq(Document::getTitle, "传统功夫").eq(Document::getCreator, "码保国")); +``` + + +```java + // 传统方式, 直接用RestHighLevelClient进行查询 需要19行代码,还不包含下划线转驼峰,自定义字段处理及_id处理等代码 + String indexName = "document"; + SearchRequest searchRequest = new SearchRequest(indexName); + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); + TermQueryBuilder titleTerm = QueryBuilders.termQuery("title", "传统功夫"); + TermsQueryBuilder creatorTerm = QueryBuilders.termsQuery("creator", "码保国"); + boolQueryBuilder.must(titleTerm); + boolQueryBuilder.must(creatorTerm); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + searchSourceBuilder.query(boolQueryBuilder); + searchRequest.source(searchSourceBuilder); + try { + SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); + List documents = Optional.ofNullable(searchResponse) + .map(SearchResponse::getHits) + .map(SearchHits::getHits) + .map(hit->Document document = JSON.parseObject(hit.getSourceAsString(),Document.class)) + .collect(Collectors.toList()); + } catch (IOException e) { + e.printStackTrace(); + } +``` +> * 以上只是简单查询演示,实际使用场景越复杂,效果就越好,平均可节省至少3-8倍代码量 +> * 传统功夫,点到为止! 上述功能仅供演示,仅为Easy-Es支持功能的冰山一角,Easy-Es就是这么Easy到不讲武德💪,不用的请耗子尾汁. + +# 架构 | Architecture + +![Architecture](https://iknow.hs.net/27fb40b8-22d4-45c2-92e0-1471112d5102.jpg) + + +# 相关链接 | Links + +- [Switch To English](https://gitee.com/easy-es/easy-es/blob/master/README_EN.md) +- [功能示例](https://gitee.com/dromara/easy-es/tree/master/easy-es-sample) +- [Springboot集成Demo](https://gitee.com/easy-es/easy-es-springboot-demo) + +# 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 + + org.dromara.easy-es + easy-es-boot-starter + Latest Version + +``` +**Gradle:** +```groovy +compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: 'Latest Version' +``` + +# 荣誉 | Honour + +> Easy-Es是一个持续成长和精进的开源框架,感谢大家一路支持,也感谢多方平台多我们努力的认可,我们会继续努力,用更好的产品力回报每一位支持者! + + +zsxq + + +# 其他开源项目 | Other Project + +- [健身计划一键生成系统](https://gitee.com/easy-es/fit-plan) + +# 期望 | Futures +--- + +> 欢迎提出更好的意见,帮助完善 Easy-Es + +# 版权 | License +--- + +[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) + +# 关注我 | About Me + +[CSDN博客](https://blog.csdn.net/lovexiaotaozi?spm=3001.5343) + +QQ | 微信:252645816 + +# 知识星球 | Planet Of Knowledge + +zsxq + +# 捐赠 | Donate + + +[捐赠记录,感谢你们的支持!](https://easy-es.cn/pages/b52ac5/) + +> 您的支持是鼓励我们前行的动力,无论金额多少都足够表达您这份心意。 + +> 如果您愿意捐赠本项目,推荐直接在右下方通过Gitee直接捐赠. + +# 广告商 | Advertising provider + +> 我们的广告投放商,如果您期望Easy-Es能够走得更远,不妨点击下图,支持一下我们的广告商Thanks♪(・ω・)ノ + + + ad + + +
+ + + ad + + + +# 赞助商 | Sponsor + +> 如果您想支持我们,奈何囊中羞涩,没事,您可以花30秒借花献佛,点击下方链接进入注册,则该赞助商会代您捐赠一笔小钱给社区开发者们买包辣条。 + + + ad + + + +# 周边好物 | Good things + + +> 老汉为社区量身打造的专属T恤,感兴趣的老板们可以点击下图链接了解详情 + + + ad + + +
+ ad From ed95bb9bfd467061914f2ee2bc1b37b09464dd4c Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:55:49 +0800 Subject: [PATCH 02/17] Update README.md --- README.md | 396 +----------------------------------------------------- 1 file changed, 5 insertions(+), 391 deletions(-) diff --git a/README.md b/README.md index 167d65a..2f74d4b 100644 --- a/README.md +++ b/README.md @@ -57,194 +57,6 @@ 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 documents = documentMapper.selectList(EsWrappers.lambdaQuery(Document.class).eq(Document::getTitle, "Hi").eq(Document::getCreator, "Guy")); -``` - -```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 - - org.dromara.easy-es - easy-es-boot-starter - Latest Version - - ``` - - 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 { - } - ``` - -- 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://easy-es.cn/#/en/). - -## Architecture - -![Architecture](https://iknow.hs.net/27fb40b8-22d4-45c2-92e0-1471112d5102.jpg) - -## MySQL Easy-Es and Es syntax comparison table - - -| 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 - - ad - - -## 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. -

- - East-Es-Logo - -

- -

- Born To Simplify Development -

- -

- - maven - - - - code style - -

- -## 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 -- ... - -## 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<>(); @@ -275,10 +87,8 @@ 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. ## 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 @@ -324,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| @@ -360,205 +169,9 @@ String indexName = "document"; | select * | matchAllQuery |QueryBuilders.matchAllQuery()| | - | highLight |HighlightBuilder.Field | | ... | ... | ...| - -## Advertising provider -

- - East-Es-Logo - -

- -

- 您的Star是我继续前进的动力,如果喜欢EE请右上角帮忙点亮星星⭐! -

- -

- - maven - - - - code style - -

- -# 官方地址 | Official website - -**easy-es官网** https://easy-es.cn/ - -**easy-es官方gitee** https://gitee.com/dromara/easy-es - -**easy-es官方github** https://github.com/dromara/easy-es - -**开源社区dromara** https://dromara.org/ - -**开源社区码云首页** https://gitee.com/dromara/ - -> **Tip:** 官网是vue单页面应用,首次访问加载可能比较慢🐢,主公们请耐心等待一下,后续会很快🏹,如偶遇打不开可刷新多尝试几次. - -# 简介 | Intro - -Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动智能索引托管. - -目前功能丰富度和易用度及性能已全面领先SpringData-Elasticsearch. - -简化`CRUD`及其它高阶操作,可以更好的帮助开发者减轻开发负担 - -底层采用Es官方提供的RestHighLevelClient,保证其原生性能及拓展性. - -技术讨论 QQ 群 :729148550 群内可在群文件中免费领取 颈椎保护 | 增肌 | 减脂 等健身计划 无套路 - -微信群请先添加作者微信,由作者拉入 (亦可咨询健身问题,作者是健身教练) - -项目推广初期,还望大家能够不吝点点三连:⭐Star,👀Watch,fork📌 - -支持一下国产开源,让更多人看到和使用本项目,非常感谢! - -# 优点 | Advantages - -- **全自动索引托管:** 全球开源首创的索引托管模式,开发者无需关心索引的创建更新及数据迁移等繁琐步骤,索引全生命周期皆可托管给框架,由框架自动完成,过程零停机,用户无感知,彻底解放开发者 -- **智能字段类型推断:** 根据索引类型和当前查询类型上下文综合智能判断当前查询是否需要拼接.keyword后缀,减少小白误用的可能 -- **屏蔽语言差异:** 开发者只需要会MySQL语法即可使用Es -- **代码量极少:** 与直接使用RestHighLevelClient相比,相同的查询平均可以节3-8倍左右的代码量 -- **零魔法值:** 字段名称直接从实体中获取,无需输入字段名称字符串这种魔法值 -- **零额外学习成本:** 开发者只要会国内最受欢迎的Mybatis-Plus语法,即可无缝迁移至Easy-Es -- **降低开发者门槛:** 即便是只了解ES基础的初学者也可以轻松驾驭ES完成绝大多数需求的开发 -- **功能强大:** 支持MySQL的几乎全部功能,且对ES特有的分词,权重,高亮,嵌套,地理位置Geo,Ip地址查询等功能都支持 -- **语法优雅:** 所有条件构造器均支持Lambda风格链式编程,编程体验和代码可读性大幅提升 -- **安全可靠:** 墨菲安全扫描零风险,且代码单元测试综合覆盖率高达95%以上. -- **完善的中英文文档:** 提供了中英文双语操作文档,文档全面可靠,帮助您节省更多时间 -- **...** - -# 对比 | Compare - -> 需求:查询出文档标题为 "传统功夫"且作者为"码保国"的所有文档 -```java - // 使用Easy-Es仅需1行代码即可完成查询 - List documents = documentMapper.selectList(EsWrappers.lambdaQuery(Document.class).eq(Document::getTitle, "传统功夫").eq(Document::getCreator, "码保国")); -``` - - -```java - // 传统方式, 直接用RestHighLevelClient进行查询 需要19行代码,还不包含下划线转驼峰,自定义字段处理及_id处理等代码 - String indexName = "document"; - SearchRequest searchRequest = new SearchRequest(indexName); - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); - TermQueryBuilder titleTerm = QueryBuilders.termQuery("title", "传统功夫"); - TermsQueryBuilder creatorTerm = QueryBuilders.termsQuery("creator", "码保国"); - boolQueryBuilder.must(titleTerm); - boolQueryBuilder.must(creatorTerm); - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.query(boolQueryBuilder); - searchRequest.source(searchSourceBuilder); - try { - SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); - List documents = Optional.ofNullable(searchResponse) - .map(SearchResponse::getHits) - .map(SearchHits::getHits) - .map(hit->Document document = JSON.parseObject(hit.getSourceAsString(),Document.class)) - .collect(Collectors.toList()); - } catch (IOException e) { - e.printStackTrace(); - } -``` -> * 以上只是简单查询演示,实际使用场景越复杂,效果就越好,平均可节省至少3-8倍代码量 -> * 传统功夫,点到为止! 上述功能仅供演示,仅为Easy-Es支持功能的冰山一角,Easy-Es就是这么Easy到不讲武德💪,不用的请耗子尾汁. - -# 架构 | Architecture - -![Architecture](https://iknow.hs.net/27fb40b8-22d4-45c2-92e0-1471112d5102.jpg) - - -# 相关链接 | Links - -- [Switch To English](https://gitee.com/easy-es/easy-es/blob/master/README_EN.md) -- [功能示例](https://gitee.com/dromara/easy-es/tree/master/easy-es-sample) -- [Springboot集成Demo](https://gitee.com/easy-es/easy-es-springboot-demo) - -# 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 - - org.dromara.easy-es - easy-es-boot-starter - Latest Version - -``` -**Gradle:** -```groovy -compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: 'Latest Version' -``` - -# 荣誉 | Honour - -> Easy-Es是一个持续成长和精进的开源框架,感谢大家一路支持,也感谢多方平台多我们努力的认可,我们会继续努力,用更好的产品力回报每一位支持者! - - -zsxq - - -# 其他开源项目 | Other Project - -- [健身计划一键生成系统](https://gitee.com/easy-es/fit-plan) - -# 期望 | Futures --- -> 欢迎提出更好的意见,帮助完善 Easy-Es - -# 版权 | License ---- - -[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) - -# 关注我 | About Me - -[CSDN博客](https://blog.csdn.net/lovexiaotaozi?spm=3001.5343) - -QQ | 微信:252645816 - -# 知识星球 | Planet Of Knowledge - -zsxq - -# 捐赠 | Donate - - -[捐赠记录,感谢你们的支持!](https://easy-es.cn/pages/b52ac5/) - -> 您的支持是鼓励我们前行的动力,无论金额多少都足够表达您这份心意。 - -> 如果您愿意捐赠本项目,推荐直接在右下方通过Gitee直接捐赠. - -# 广告商 | Advertising provider - -> 我们的广告投放商,如果您期望Easy-Es能够走得更远,不妨点击下图,支持一下我们的广告商Thanks♪(・ω・)ノ - - - ad - - -
- - - ad - - - -# 赞助商 | Sponsor - -> 如果您想支持我们,奈何囊中羞涩,没事,您可以花30秒借花献佛,点击下方链接进入注册,则该赞助商会代您捐赠一笔小钱给社区开发者们买包辣条。 - - - ad - - - -# 周边好物 | Good things - - -> 老汉为社区量身打造的专属T恤,感兴趣的老板们可以点击下图链接了解详情 +## Advertising provider ad @@ -566,11 +179,12 @@ QQ | 微信:252645816
-
ad + ## Donate [Donate Easy-Es](https://en.easy-es.cn/pages/fb291d/) From a139fefe4b93eb412a446f9c003792e91549c879 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:52:13 +0800 Subject: [PATCH 03/17] Update README-ZH.md --- README-ZH.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README-ZH.md b/README-ZH.md index efbc8c0..74b6095 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -171,6 +171,12 @@ QQ | 微信:252645816 > 我们的广告投放商,如果您期望Easy-Es能够走得更远,不妨点击下图,支持一下我们的广告商Thanks♪(・ω・)ノ + + ad + + +
+ ad From 8f00a95dcd74ad8339ec0bcdb7843823954d91d8 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:52:40 +0800 Subject: [PATCH 04/17] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 2f74d4b..c25a3fd 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,12 @@ String indexName = "document"; ## Advertising provider + + ad + + +
+ ad From e3e64daf63299d6ac47d6ab2f831e58c4c7ea182 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:26:10 +0800 Subject: [PATCH 05/17] Update README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c25a3fd..dfaee2c 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,9 @@ String indexName = "document"; ## Advertising provider - - ad + + ad
@@ -185,12 +186,10 @@ String indexName = "document";
- - ad + + ad - ## Donate [Donate Easy-Es](https://en.easy-es.cn/pages/fb291d/) From a3ae2a050efdff7c0bfc3485ecf6dcf7e12fd52c Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:28:32 +0800 Subject: [PATCH 06/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dfaee2c..eb897a1 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ String indexName = "document";
- ad + ad ## Donate From 2efe0ca2768ba555f525c4828bb26e1d69e1ee5f Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:29:45 +0800 Subject: [PATCH 07/17] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index eb897a1..e0d55b0 100644 --- a/README.md +++ b/README.md @@ -180,12 +180,15 @@ String indexName = "document";
+ ad +
+ ad From 39ac6750fccc70d4cb67aaa459c99e8472309403 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:31:53 +0800 Subject: [PATCH 08/17] Update README-ZH.md --- README-ZH.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README-ZH.md b/README-ZH.md index 74b6095..abf83b3 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -171,8 +171,8 @@ QQ | 微信:252645816 > 我们的广告投放商,如果您期望Easy-Es能够走得更远,不妨点击下图,支持一下我们的广告商Thanks♪(・ω・)ノ - - ad + + ad
@@ -183,8 +183,8 @@ QQ | 微信:252645816
- - ad + + ad From 617bea1aa314cadef573111a8e455958b4fe67b9 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:23:00 +0800 Subject: [PATCH 09/17] Update README-ZH.md --- README-ZH.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README-ZH.md b/README-ZH.md index abf83b3..213414a 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -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 From dc3d753d90fbfb78f6df904c66ac019d4a58954f Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:31:09 +0800 Subject: [PATCH 10/17] Update README-ZH.md --- README-ZH.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README-ZH.md b/README-ZH.md index 213414a..944e966 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -57,7 +57,7 @@ Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动 - **全自动索引托管:** 全球开源首创的索引托管模式,开发者无需关心索引的创建更新及数据迁移等繁琐步骤,索引全生命周期皆可托管给框架,由框架自动完成,过程零停机,用户无感知,彻底解放开发者 - **智能字段类型推断:** 根据索引类型和当前查询类型上下文综合智能判断当前查询是否需要拼接.keyword后缀,减少小白误用的可能 - **屏蔽语言差异:** 开发者只需要会MySQL语法即可使用Es -- **代码量极少:** 与直接使用RestHighLevelClient相比,相同的查询平均可以节3-8倍左右的代码量 +- **代码量极少:** 与直接使用RestHighLevelClient相比,相同的查询平均可以节3-80倍左右的代码量 - **零魔法值:** 字段名称直接从实体中获取,无需输入字段名称字符串这种魔法值 - **零额外学习成本:** 开发者只要会国内最受欢迎的Mybatis-Plus语法,即可无缝迁移至Easy-Es - **降低开发者门槛:** 即便是只了解ES基础的初学者也可以轻松驾驭ES完成绝大多数需求的开发 @@ -99,7 +99,7 @@ Easy-Es是一款简化ElasticSearch搜索引擎操作的开源框架,全自动 e.printStackTrace(); } ``` -> * 以上只是简单查询演示,实际使用场景越复杂,效果就越好,平均可节省至少3-8倍代码量 +> * 以上只是简单查询演示,实际使用场景越复杂,效果就越好,平均可节省至少3-80倍代码量 > * 传统功夫,点到为止! 上述功能仅供演示,仅为Easy-Es支持功能的冰山一角,Easy-Es就是这么Easy到不讲武德💪,不用的请耗子尾汁. # 架构 | Architecture From 2f3db80c6ef6fc9e0dca94351ca6f12deb0a940b Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:31:53 +0800 Subject: [PATCH 11/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0d55b0..63bdbf7 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ 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 - Add Easy-Es dependency From 30ba3c9faf1c6e3af83f022fb47f4303f9cd7f48 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:12:56 +0800 Subject: [PATCH 12/17] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 6a66338..8a561cf 100644 --- a/README.md +++ b/README.md @@ -367,6 +367,12 @@ String indexName = "document"; ad +
+ + + ad + + ## Donate [Donate Easy-Es](https://en.easy-es.cn/pages/fb291d/) From 5daf30f99213a3a73396b531b4a44a51bb2cc468 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:19:55 +0800 Subject: [PATCH 13/17] Update README-ZH.md --- README-ZH.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README-ZH.md b/README-ZH.md index efbc8c0..934ed5e 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -181,6 +181,12 @@ QQ | 微信:252645816 ad +
+ + + ad + + # 赞助商 | Sponsor From e69853d6402fd1a3eaccd9252a880a4d7f79b8a4 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:32:23 +0800 Subject: [PATCH 14/17] Update README-ZH.md --- README-ZH.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-ZH.md b/README-ZH.md index cecaa5f..7fabd27 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -139,7 +139,7 @@ compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: 'La # 其他开源项目 | Other Project - +- [零侵入全自动接口文档生成框架](https://www.doc-apis.com) - [健身计划一键生成系统](https://gitee.com/easy-es/fit-plan) # 期望 | Futures From 3c6c7f521303e1dbe3a9d6d8108a54330ac71bb9 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:12:54 +0800 Subject: [PATCH 15/17] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fe27965..d88bde5 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ Easy-Es is a powerfully enhanced toolkit of RestHighLevelClient for simplify dev **easy-es website** https://en.easy-es.cn/ +**easy-es gitcode** https://gitcode.com/dromara/easy-es + **easy-es gitee** https://gitee.com/dromara/easy-es **easy-es github** https://github.com/dromara/easy-es From 4678ea4b9ebddb81d8d9c883fb4db003ec534086 Mon Sep 17 00:00:00 2001 From: elastic search <38153520+xpc1024@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:13:29 +0800 Subject: [PATCH 16/17] Update README-ZH.md --- README-ZH.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README-ZH.md b/README-ZH.md index 7fabd27..7f727e0 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -22,6 +22,8 @@ **easy-es官网** https://easy-es.cn/ +**easy-es官方gitcode** https://gitcode.com/dromara/easy-es + **easy-es官方gitee** https://gitee.com/dromara/easy-es **easy-es官方github** https://github.com/dromara/easy-es From 3cfd077377bbb7fa130f7590c1c9667d7d46ff45 Mon Sep 17 00:00:00 2001 From: wenzb <1751902289@qq.com> Date: Fri, 26 Jul 2024 17:44:29 +0800 Subject: [PATCH 17/17] =?UTF-8?q?feature=20#122=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=85=A8=E9=87=8F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easyes/core/kernel/BaseEsMapper.java | 8 + .../easyes/core/kernel/BaseEsMapperImpl.java | 174 +++++++++++++++--- .../org/dromara/easyes/test/all/AllTest.java | 23 ++- 3 files changed, 182 insertions(+), 23 deletions(-) diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapper.java b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapper.java index 1257e3e..de7dd32 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapper.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapper.java @@ -592,4 +592,12 @@ public interface BaseEsMapper { * @return 是否成功 */ Boolean setRequestOptions(RequestOptions requestOptions); + + /** + * 查询全部记录. + * + * @param wrapper 参数包装类 + * @return 指定对象的列表 + */ + List selectAll(Wrapper wrapper); } diff --git a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java index 7f98d65..b73a880 100644 --- a/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java +++ b/easy-es-core/src/main/java/org/dromara/easyes/core/kernel/BaseEsMapperImpl.java @@ -12,12 +12,26 @@ import org.dromara.easyes.annotation.rely.IdType; import org.dromara.easyes.annotation.rely.JoinField; import org.dromara.easyes.annotation.rely.RefreshPolicy; -import org.dromara.easyes.common.constants.BaseEsConstants; import org.dromara.easyes.common.enums.EsQueryTypeEnum; import org.dromara.easyes.common.enums.MethodEnum; import org.dromara.easyes.common.enums.OrderTypeEnum; -import org.dromara.easyes.common.utils.*; -import org.dromara.easyes.core.biz.*; +import org.dromara.easyes.common.utils.ArrayUtils; +import org.dromara.easyes.common.utils.Assert; +import org.dromara.easyes.common.utils.CollectionUtils; +import org.dromara.easyes.common.utils.ExceptionUtils; +import org.dromara.easyes.common.utils.FastJsonUtils; +import org.dromara.easyes.common.utils.LogUtils; +import org.dromara.easyes.common.utils.NumericUtils; +import org.dromara.easyes.common.utils.ReflectionKit; +import org.dromara.easyes.common.utils.StringUtils; +import org.dromara.easyes.core.biz.BaseSortParam; +import org.dromara.easyes.core.biz.CreateIndexParam; +import org.dromara.easyes.core.biz.EntityFieldInfo; +import org.dromara.easyes.core.biz.EntityInfo; +import org.dromara.easyes.core.biz.EsIndexParam; +import org.dromara.easyes.core.biz.EsPageInfo; +import org.dromara.easyes.core.biz.EsUpdateParam; +import org.dromara.easyes.core.biz.SAPageInfo; import org.dromara.easyes.core.cache.BaseCache; import org.dromara.easyes.core.cache.GlobalConfigCache; import org.dromara.easyes.core.config.GlobalConfig; @@ -34,6 +48,7 @@ import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.ClearScrollRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; @@ -50,12 +65,14 @@ import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.core.TimeValue; 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; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.metrics.ParsedCardinality; @@ -66,11 +83,36 @@ import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; - -import static org.dromara.easyes.common.constants.BaseEsConstants.*; +import java.util.stream.Stream; + +import static org.dromara.easyes.common.constants.BaseEsConstants.DEFAULT_ES_ID_NAME; +import static org.dromara.easyes.common.constants.BaseEsConstants.DSL_ENDPOINT; +import static org.dromara.easyes.common.constants.BaseEsConstants.DSL_PREFIX; +import static org.dromara.easyes.common.constants.BaseEsConstants.EMPTY_STR; +import static org.dromara.easyes.common.constants.BaseEsConstants.I_KUN_PREFIX; +import static org.dromara.easyes.common.constants.BaseEsConstants.MINUS_ONE; +import static org.dromara.easyes.common.constants.BaseEsConstants.ONE; +import static org.dromara.easyes.common.constants.BaseEsConstants.PAGE_NUM; +import static org.dromara.easyes.common.constants.BaseEsConstants.PAGE_SIZE; +import static org.dromara.easyes.common.constants.BaseEsConstants.QUERY; +import static org.dromara.easyes.common.constants.BaseEsConstants.REPEAT_NUM_KEY; +import static org.dromara.easyes.common.constants.BaseEsConstants.SQL_ENDPOINT; +import static org.dromara.easyes.common.constants.BaseEsConstants.STR_SIGN; +import static org.dromara.easyes.common.constants.BaseEsConstants.ZERO; /** * 核心 所有支持方法接口实现类 @@ -243,8 +285,8 @@ public String getSource(Wrapper wrapper) { @Override public EsPageInfo pageQuery(Wrapper 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; + pageNum = pageNum == null || pageNum <= ZERO ? PAGE_NUM : pageNum; + pageSize = pageSize == null || pageSize <= ZERO ? PAGE_SIZE : pageSize; wrapper.from = (pageNum - 1) * pageSize; wrapper.size = pageSize; @@ -276,7 +318,7 @@ public SAPageInfo searchAfterPage(Wrapper wrapper, List searchAfte } // 兼容分页参数 - pageSize = pageSize == null || pageSize <= BaseEsConstants.ZERO ? BaseEsConstants.PAGE_SIZE : pageSize; + pageSize = pageSize == null || pageSize <= ZERO ? PAGE_SIZE : pageSize; wrapper.size = pageSize; // 请求es获取数据 @@ -393,7 +435,7 @@ public Integer insertBatch(String routing, Collection entityList, String... i public Integer insertBatch(String routing, String parentId, Collection entityList, String... indexNames) { // 老汉裤子都脱了 你告诉我没有数据 怎么*入? if (CollectionUtils.isEmpty(entityList)) { - return BaseEsConstants.ZERO; + return ZERO; } // 在每条指定的索引上批量执行数据插入 @@ -516,7 +558,7 @@ public Integer updateBatchByIds(Collection entityList, String... indexNames) @Override public Integer updateBatchByIds(String routing, Collection entityList, String... indexNames) { if (CollectionUtils.isEmpty(entityList)) { - return BaseEsConstants.ZERO; + return ZERO; } // 在每条指定索引上批量执行更新 @@ -528,7 +570,7 @@ public Integer updateBatchByIds(String routing, Collection entityList, String @Override public Integer update(T entity, Wrapper updateWrapper) { if (Objects.isNull(entity) && CollectionUtils.isEmpty(updateWrapper.updateParamList)) { - return BaseEsConstants.ZERO; + return ZERO; } // 在每条指定索引上执行更新操作 @@ -641,7 +683,21 @@ public Boolean setRequestOptions(RequestOptions requestOptions) { } return Boolean.TRUE; } - + + @Override + public List selectAll(Wrapper wrapper) { + // 请求es获取数据 + SearchHit[] searchHits = getAllSearchHitArray(wrapper); + if (ArrayUtils.isEmpty(searchHits)) { + return Collections.emptyList(); + } + + // 批量解析 + return Arrays.stream(searchHits) + .map(searchHit -> parseOne(searchHit, wrapper)) + .collect(Collectors.toList()); + } + /** * 执行创建索引 * @@ -728,10 +784,10 @@ private Integer doInsert(T entity, String routing, String parentId, String index IndexResponse indexResponse = client.index(indexRequest, getRequestOptions()); if (Objects.equals(indexResponse.status(), RestStatus.CREATED)) { setId(entity, indexResponse.getId()); - return BaseEsConstants.ONE; + return ONE; } else if (Objects.equals(indexResponse.status(), RestStatus.OK)) { // 该id已存在,数据被更新的情况 - return BaseEsConstants.ZERO; + return ZERO; } else { throw ExceptionUtils.eee("insert failed, result:%s entity:%s", indexResponse.getResult(), entity); } @@ -779,12 +835,12 @@ private Integer doDeleteById(Serializable id, String routing, String indexName) try { DeleteResponse deleteResponse = client.delete(deleteRequest, getRequestOptions()); if (Objects.equals(deleteResponse.status(), RestStatus.OK)) { - return BaseEsConstants.ONE; + return ONE; } } catch (IOException e) { throw ExceptionUtils.eee("deleteById exception, id:%s", e, id.toString()); } - return BaseEsConstants.ZERO; + return ZERO; } @@ -826,13 +882,13 @@ private Integer doUpdateById(T entity, String idValue, String routing, String in try { UpdateResponse updateResponse = client.update(updateRequest, getRequestOptions()); if (Objects.equals(updateResponse.status(), RestStatus.OK)) { - return BaseEsConstants.ONE; + return ONE; } } catch (IOException e) { throw ExceptionUtils.eee("updateById exception,entity:%s", e, entity.toString()); } - return BaseEsConstants.ZERO; + return ZERO; } /** @@ -870,7 +926,7 @@ private Integer doUpdate(T entity, Wrapper updateWrapper, String indexName) { // 查询数据列表 List list = selectListByUpdateWrapper(updateWrapper, indexName); if (CollectionUtils.isEmpty(list)) { - return BaseEsConstants.ZERO; + return ZERO; } // 获取更新文档内容 @@ -1131,7 +1187,7 @@ private long parseCount(SearchResponse response, boolean distinct) { if (distinct) { Optional.ofNullable(response.getAggregations()) .ifPresent(aggregations -> { - ParsedCardinality parsedCardinality = aggregations.get(BaseEsConstants.REPEAT_NUM_KEY); + ParsedCardinality parsedCardinality = aggregations.get(REPEAT_NUM_KEY); Optional.ofNullable(parsedCardinality).ifPresent(p -> repeatNum.getAndAdd(p.getValue())); }); } else { @@ -1427,6 +1483,82 @@ private SearchHit[] getSearchHitArray(Wrapper wrapper) { printResponseErrors(response); return parseSearchHitArray(response); } + + /** + * 获取所有数据. + * + * @param searchRequest 请求参数 + * @return SearchHit数组 + */ + private SearchHit[] getAllSearchHitArray(SearchRequest searchRequest) { + Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1)); + searchRequest.scroll(scroll); + printDSL(searchRequest); + String scrollId = null; + Stream.Builder builder; + try { + SearchResponse response = client.search(searchRequest, getRequestOptions()); + scrollId = response.getScrollId(); + builder = Stream.builder(); + while (response.getHits().getHits().length != 0) { + printResponseErrors(response); + SearchHit[] searchHits = parseSearchHitArray(response); + builder.add(searchHits); + SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); + scrollRequest.scroll(scroll); + try { + response = client.scroll(scrollRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + throw ExceptionUtils.eee("scroll IOException, searchRequest:%s", e, searchRequest.toString()); + } + + } + } catch (IOException e) { + throw ExceptionUtils.eee("getAllSearchHitArray IOException, searchRequest:%s", e, searchRequest.toString()); + } finally { + clearScroll(scrollId); + } + return builder.build().flatMap(Stream::of).toArray(SearchHit[]::new); + } + + /** + * 获取所有数据. + * + * @param wrapper 参数包装类 + * @return SearchHit数组 + */ + private SearchHit[] getAllSearchHitArray(Wrapper wrapper) { + SearchRequest searchRequest = new SearchRequest(getIndexNames(wrapper.indexNames)); + Optional.ofNullable(wrapper.routing).ifPresent(searchRequest::routing); + Optional.ofNullable(wrapper.preference).ifPresent(searchRequest::preference); + + // 用户在wrapper中指定的混合查询条件优先级最高 + SearchSourceBuilder searchSourceBuilder = + Objects.isNull(wrapper.searchSourceBuilder) ? WrapperProcessor.buildSearchSourceBuilder(wrapper, + entityClass) : wrapper.searchSourceBuilder; + searchRequest.source(searchSourceBuilder); + return getAllSearchHitArray(searchRequest); + } + + /** + * 清除scroll. + * + * @param scrollId scrollId + */ + private void clearScroll(String scrollId) { + if (StringUtils.isEmpty(scrollId)) { + return; + } + ClearScrollRequest clearScrollRequest = null; + try { + clearScrollRequest = new ClearScrollRequest(); + clearScrollRequest.addScrollId(scrollId); + client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + throw ExceptionUtils.eee("clearScroll IOException, clearScrollRequest:%s", e, + clearScrollRequest.toString()); + } + } /** * 构建,插入/更新 的JSON对象 diff --git a/easy-es-test/src/test/java/org/dromara/easyes/test/all/AllTest.java b/easy-es-test/src/test/java/org/dromara/easyes/test/all/AllTest.java index 8e91fe9..309dd90 100644 --- a/easy-es-test/src/test/java/org/dromara/easyes/test/all/AllTest.java +++ b/easy-es-test/src/test/java/org/dromara/easyes/test/all/AllTest.java @@ -39,14 +39,24 @@ import org.elasticsearch.search.sort.GeoDistanceSortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import static org.dromara.easyes.common.constants.BaseEsConstants.KEYWORD_SUFFIX; @@ -259,6 +269,15 @@ public void testSelectList() { List documents = documentMapper.selectList(wrapper); Assertions.assertEquals(22, documents.size()); } + + @Test + @Order(6) + public void testSelectAll() { + LambdaEsQueryWrapper wrapper = new LambdaEsQueryWrapper<>(); + wrapper.match(Document::getCreator, "老汉"); + List documents = documentMapper.selectAll(wrapper); + Assertions.assertEquals(22, documents.size()); + } @Test @Order(6)