首页
/ Easy-Es 开源项目教程

Easy-Es 开源项目教程

2026-01-23 04:06:47作者:董斯意

1. 项目介绍

Easy-Es 是一个为简化 Elasticsearch 开发而设计的 ORM 框架。它通过提供高效的、开箱即用的功能,帮助开发者减少编码量,提升开发效率。使用 Easy-Es,开发者可以用类似 MySQL 的语法来完成 Elasticsearch 的查询操作。

主要特点

  • 自动创建和更新索引:自动迁移数据,实现零停机时间。
  • 自动配置:启动时自动配置。
  • 灵活的查询条件:支持 Lambda 风格的 API,自动分页操作。
  • 高级语法支持:支持高亮、权重、Geo 等高级语法。

2. 项目快速启动

2.1 添加依赖

首先,在你的项目中添加 Easy-Es 的依赖。

Maven

<dependency>
    <groupId>org.dromara.easy-es</groupId>
    <artifactId>easy-es-boot-starter</artifactId>
    <version>最新版本</version>
</dependency>

Gradle

compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: '最新版本'

2.2 创建 Mapper 接口

创建一个继承自 BaseEsMapper 的接口。

public interface DocumentMapper extends BaseMapper<Document> {
}

2.3 使用 Easy-Es 进行查询

使用 LambdaEsQueryWrapper 进行查询操作。

LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Hello World")
       .eq(Document::getCreator, "Guy");

List<Document> documentList = documentMapper.selectList(wrapper);

3. 应用案例和最佳实践

3.1 案例一:文档搜索

假设你需要在一个文档库中搜索标题为 "Hi" 且作者为 "Guy" 的所有文档。

List<Document> documents = documentMapper.selectList(
    EsWrappers.lambdaQuery(Document.class)
              .eq(Document::getTitle, "Hi")
              .eq(Document::getCreator, "Guy")
);

3.2 案例二:高级查询

使用 Easy-Es 进行复杂查询,例如高亮显示搜索结果。

LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Hello World")
       .eq(Document::getCreator, "Guy")
       .highLight(Document::getContent);

List<Document> documentList = documentMapper.selectList(wrapper);

4. 典型生态项目

4.1 Spring Boot 集成

Easy-Es 可以与 Spring Boot 无缝集成,提供自动配置和简化开发的功能。

4.2 数据迁移工具

Easy-Es 提供了数据迁移工具,帮助开发者自动处理索引的创建和更新,确保数据迁移的顺利进行。

4.3 高级查询扩展

Easy-Es 支持多种高级查询扩展,如 Geo 查询、权重查询等,满足复杂业务需求。

通过以上模块的介绍,你可以快速上手并深入了解 Easy-Es 的使用和最佳实践。

登录后查看全文
热门项目推荐
相关项目推荐