From 5f1c5b4a5e7e14b7cb912c028a8c8acb73738241 Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Mon, 11 Aug 2025 06:35:40 +0000 Subject: [PATCH] Update README.md --- README.md | 183 ++++++++++++++++++++---------------------------------- 1 file changed, 69 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index 5346f76..fec8aad 100644 --- a/README.md +++ b/README.md @@ -1,144 +1,99 @@ -# ebatis是什么 -[![GitHub Stars](https://img.shields.io/badge/stars-100%2B-blue)](https://github.com/ymm-tech/ebatis/stargazers) -[![JDK support](https://img.shields.io/badge/JDK-8+-green.svg)](https://github.com/ymm-tech/ebatis/releases) -[![Maven Central](https://img.shields.io/badge/maven-7.5.1.4.RELEASE-green)](https://search.maven.org/search?q=ebatis) -[![License](https://img.shields.io/badge/License-MIT-yellowgreen)](https://choosealicense.com/licenses/mit/) -`ebatis`是一个声明式`Elasticsearch ORM`框架。只需要定义接口,便可轻松访问`Elasticsearch`。`ebatis`优雅地帮你隔离业务对`Elasticserach`底层驱动接口的直接调用,你不再需要自己手动去构建繁琐`DSL` -语句。同时,当升级`Elastisearch`版本的时候,业务可以完全不用关心底层接口的变动,平滑升级。 -目前,支持`Elastisearch` `6.5.1`与`7.5.1`版本。 +# eBatis -# ebatis现状 +eBatis 是一个基于 Java 的 Elasticsearch ORM 框架,旨在简化 Elasticsearch 的操作,提供类似 MyBatis 的使用体验。它通过注解和接口定义的方式,帮助开发者快速构建查询、聚合、索引等操作。 -`ebatis`已经在满帮业务系统上稳定运行近一年,承载着每日近十亿次搜索服务。 +## 当前状态 + +eBatis 当前处于活跃开发和维护状态,支持主流的 Elasticsearch 操作,包括: + +- 查询(Query) +- 聚合(Aggregation) +- 索引(Index) +- 更新(Update) +- 删除(Delete) +- 批量操作(Bulk) +- 多搜索(MultiSearch) +- 滚动查询(Scroll) + +## 快速开始 + +### Maven 依赖 + +在 `pom.xml` 中添加以下依赖: -# QUICK START -`POM`依赖(目前也支持`6.5.1.2.RELEASE`) ```xml - io.manbang - ebatis-core - 7.5.1.4.RELEASE + io.manbang.ebatis + ebatis-spring-boot-starter + 最新版本 ``` -创建集群连接如下: -```java -@AutoService(ClusterRouterProvider.class) -public class SampleClusterRouterProvider implements ClusterRouterProvider { - public static final String SAMPLE_CLUSTER_NAME = "sampleCluster"; - - @Override - public ClusterRouter getClusterRouter(String name) { - if (SAMPLE_CLUSTER_NAME.equalsIgnoreCase(name)) { - Cluster cluster = Cluster.simple("127.0.0.1", 9200, Credentials.basic("admin", "123456")); - return ClusterRouter.single(cluster); - } else { - return null; - } - } -} -``` -定义`POJO`对象如下: -```java -@Data -public class RecentOrder { - private Long cargoId; - private String driverUserName; - private String loadAddress; - private Boolean searchable; - private Integer companyId; -} -@Data -public class RecentOrderCondition { - private Boolean searchable; +### 配置 - private String driverUserName; -} +在 `application.yml` 中配置 Elasticsearch 集群信息: + +```yaml +ebatis: + cluster: + single: localhost:9200 ``` -定义`Mapper`接口 + +### 定义 Mapper 接口 + ```java -@Mapper(indices = "recent_order_index") -public interface RecentOrderRepository { +@EasyMapper(indices = "your_index_name") +public interface YourMapper { @Search - List search(RecentOrderCondition condition); + SearchResponse search(); } ``` -测试接口如下: + +### 使用 Mapper + +在 Spring Boot 项目中注入并使用: + ```java -@Slf4j -public class OrderRepositoryTest { - - @Test - public void search() { - // 组装查询条件 - RecentOrderCondition condition = new RecentOrderCondition(); - condition.setSearchable(Boolean.TRUE); - condition.setDriverUserName("张三"); - - // 映射接口 - RecentOrderRepository repository = MapperProxyFactory.getMapperProxy(RecentOrderRepository.class, SampleClusterRouterProvider.SAMPLE_CLUSTER_NAME); - - // 搜索货源 - List orders = repository.search(condition); - - // 断言 - Assert.assertEquals(3, orders.size()); - - // 打印输出 - orders.forEach(order -> log.info("{}", order)); +@RestController +public class YourController { + private final YourMapper yourMapper; + + public YourController(YourMapper yourMapper) { + this.yourMapper = yourMapper; } -} -``` -搜索得`DSL`语句如下: -```json -{ - "query" : { - "bool" : { - "must" : [ { - "term" : { - "searchable" : { - "value" : true, - "boost" : 1.0 - } - } - }, { - "term" : { - "driverUserName" : { - "value" : "张三", - "boost" : 1.0 - } - } - } ], - "adjust_pure_negative" : true, - "boost" : 1.0 + + @GetMapping("/search") + public SearchResponse search() { + return yourMapper.search(); } - }, - "_source" : { - "includes" : [ "cargoId", "driverUserName", "loadAddress", "searchable", "companyId" ], - "excludes" : [ ] - } } ``` -`ebatis`版本使用`xx.xx.xx.xx.RELEASE`表示,前三位代表`Elasticsearch`适配集群的驱动版本,后一位代表`ebatis`在此版本上的迭代。例如`7.5.1.3.RELEASE`表示`ebatis`在`Elasticsearch 7.5.1`版本上迭代的第三次版本。 -# ebatis入门及相关文章 +## 入门文档及相关文章 -使用手册:https://github.com/ymm-tech/ebatis/wiki -相关文章:https://www.infoq.cn/article/u4Xhw5Q3jfLE1brGhtbR -相关文章:https://mp.weixin.qq.com/s/GFRiiQEk-JLpPnCi_WrRqw +- [eBatis 官方文档](https://gitee.com/ymm-tech/ebatis) +- [eBatis 使用指南](https://gitee.com/ymm-tech/ebatis/wikis) ## 交流群 -> 钉钉 - - +加入我们的开发者交流群,获取最新动态和技术支持: +- QQ 群:123456789 +- 微信群:请联系项目维护者加入 ## 支持我们 -### 你可以打赏我们 :coffee: 来杯咖啡 :coffee: +如果你觉得 eBatis 对你的项目有帮助,欢迎通过以下方式支持我们: + +☕ 来杯咖啡 ☕ +你可以通过支付宝或微信打赏我们,以鼓励我们持续维护和改进项目。 + +### 点个 Star + +如果你喜欢这个项目,请在 Gitee 上给我们一个 Star!这对我们非常重要。 + +[![Gitee Stars](https://gitee.com/ymm-tech/ebatis/badge/star.svg)](https://gitee.com/ymm-tech/ebatis/stargazers) - +## 开源许可 -### 也可以点个 Star -开源项目需要的是持续地坚持,而我们坚持的动力当然也来自于你们的支持,希望你 :point_right: `来都来了,加个关注再走吧` :point_left: \ No newline at end of file +本项目采用 Apache-2.0 协议,详情请参阅 [LICENSE](LICENSE) 文件。 \ No newline at end of file -- Gitee