Boost Your Elasticsearch Development with Easy-Es: A Complete Guide
This article introduces Easy-Es, an ORM framework built on Elasticsearch's RestHighLevelClient, explains its architecture and advantages, and provides step‑by‑step instructions—including Maven/Gradle setup, configuration, entity and mapper creation, and full CRUD test examples—so developers can quickly integrate powerful search capabilities into Spring Boot applications.
Overview
Easy-Es (EE) is an open‑source ORM framework for Elasticsearch that builds on the official RestHighLevelClient. It provides MyBatis‑Plus‑like APIs to simplify index definition, CRUD, and query operations while keeping the underlying client unchanged.
Key Use Cases
Search‑oriented services (document libraries, e‑commerce product search, log retrieval).
Question‑answer or chatbot services.
Geolocation services (ride‑hailing, food delivery, community group buying, social networking).
Architecture
Advantages
Dependency
Maven:
<dependency>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-boot-starter</artifactId>
<version><!-- latest version, e.g. 2.0.0 --></version>
</dependency>
<!-- Exclude Spring Boot's built‑in Elasticsearch client to avoid conflicts -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.14.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.14.0</version>
</dependency>Gradle:
compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: 'Latest Version'Configuration
Add the following to application.yml:
easy-es:
enable: true # default true, set false to disable
address: 127.0.0.1:9200 # single node or comma‑separated list for clusters
username: elastic # optional
password: your_password # optionalEnable mapper scanning in the Spring Boot main class:
@SpringBootApplication
@EsMapperScan("com.xpc.easyes.sample.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}Sample Entity and Mapper
Entity class (uses Lombok for brevity):
@Data
@IndexName
public class Document {
/** ES unique id */
private String id;
/** Document title */
private String title;
/** Document content */
private String content;
}Mapper interface extending the framework base mapper:
public interface DocumentMapper extends BaseEsMapper<Document> {}Index Creation
Create the index in manual mode (default). The framework generates the mapping from the annotations:
@Test
public void testCreateIndex() {
boolean success = documentMapper.createIndex();
Assertions.assertTrue(success);
}CRUD Operations
Insert a document:
@Test
public void testInsert() {
Document doc = new Document();
doc.setTitle("老汉");
doc.setContent("技术过硬");
int count = documentMapper.insert(doc);
System.out.println(count);
}Query by title (chain style similar to MyBatis‑Plus):
@Test
public void testSelect() {
String title = "老汉";
Document doc = EsWrappers.lambdaChainQuery(documentMapper)
.eq(Document::getTitle, title)
.one();
System.out.println(doc);
Assert.assertEquals(title, doc.getTitle());
}Update documents matching a condition:
@Test
public void testUpdate() {
LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
wrapper.eq(Document::getTitle, "oldTitle");
Document newDoc = new Document();
newDoc.setTitle("隔壁老李");
newDoc.setContent("技术过软");
documentMapper.update(newDoc, wrapper);
}Delete documents matching a condition:
@Test
public void testDelete() {
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "隔壁老李");
int count = documentMapper.delete(wrapper);
System.out.println(count);
}Project Resources
Source repository: https://gitee.com/dromara/easy-es
Official site: https://www.easy-es.cn/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
