Easy-Es Easy-Es
💋Home
  • v2.0.0(current version)
  • What's New

    • What' s New In Easy-Es v2.0.0?
  • history version

    • v1.x.x
  • Upgrade guide

    • Upgrade to 2.x.x instructions
💖Support
  • OS Community
  • Recommend Goods
  • Project PPT (opens new window)
  • Project introduction
  • Project members
  • PR
Join
Customer
  • Doc-Apis (opens new window)
  • Fitness plan automatic generation system (opens new window)
  • Vuepress-theme-vdoing (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)

adv display by random ❤️become sponsor
💋Home
  • v2.0.0(current version)
  • What's New

    • What' s New In Easy-Es v2.0.0?
  • history version

    • v1.x.x
  • Upgrade guide

    • Upgrade to 2.x.x instructions
💖Support
  • OS Community
  • Recommend Goods
  • Project PPT (opens new window)
  • Project introduction
  • Project members
  • PR
Join
Customer
  • Doc-Apis (opens new window)
  • Fitness plan automatic generation system (opens new window)
  • Vuepress-theme-vdoing (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • Quick start

    • Introduction.md
    • Applicable scene
    • Worry free
    • Avoid pit
    • Quick start
      • Initialize the project
      • Add dependencies
      • ✨ Latest Version Latest Version: ![Maven Central](https://search.maven.org/search?q=g:io.github.xpc1024%20a:easy-*)
      • Configuration
      • Background
      • Coding
      • Getting Started (CRUD)
    • Springboot demo
    • Spring Integration Guide
    • Solon Integration Guide
    • Config
    • Annotation
  • Core function

    • Condition constructor

      • Introduction of Wrapper
      • Index wrapper
      • Select wrapper
      • Update wrapper
    • Index CRUD

      • Index hosting model
      • Index CRUD
    • Data CRUD

      • Data synchronization solutions
      • Data CRUD
    • Multiple data sources support
    • Dynamic indexing support
    • Four nested query
    • Chain call
  • Extended function

    • Mixed query
    • Origin query
    • Page
    • Nested
    • Join parent child
    • Get DSL
    • ExecuteDSL
    • Execute SQL
    • Custom RequestOptions
    • Custom default method
  • High-level syntax

    • Field filtering
    • Sort
    • Aggregation
    • Match&fuzzy match
    • Weight
    • Highlight
    • Geo
    • IP
  • Plugin

    • Plugin
  • Other

    • Faq
    • Difference from MP
    • MySQL and EE syntax comparison
    • Update log
    • Update plan
    • Copyright
    • Thanks
  • v2.xDoc
  • Quick start
LaoHan
2023-03-18
目录

Quick start

提示

If you have used Mybatis-Plus, you can basically get started without having to read more than this documentation Easy-Es is a flat version of Mybatis-Plus for Elastic Search.

We will illustrate the power of Easy-Es with a simple demo, before that we assume that you have.

  • Have a Java development environment and the appropriate IDE
  • Familiarity with MySQL
  • Familiarity with Spring Boot (recommended version 2.5.x +)
  • Familiarity with Maven
  • Understand the basic concepts of Es or have read the avoidance guide (highly recommended)
  • Es installed recommended version 7.x (not installed by their own Baidu tutorials, it is recommended to install an es-head plug-in, to facilitate visual verification), low version may exist API incompatibility or other unknown cases, because the underlying RestHighLevelClient rather than RestLowLevelClient, the demo uses Es version is 7.17.8

Recommended

We recommend you to refer to this Springboot integration demo, it will help you save more time.

Special Note

Because springboot has a built-in version of es, different versions of springboot may cause the actual project to introduce a low or high version of es dependency, Many users have stepped into some compatibility problems due to conflicting dependencies, so we would like to remind you that if the actual es version that your project depends on is not 7.17.8 version, we strongly recommend that you show the specified es dependency jar package version for 7.17.8, and we use the underlying es dependency version to maintain consistency, so the best compatibility, It is not easy to step in the hole. The reason for the underlying 7.17.8 is also after much research, the choice of a stable version without security vulnerabilities, by Murphy scan the version is safe and reliable. As for the ES client version, 7.10+ tested compatibility are very good, the dependency of the jar package version and the client version does not matter, the focus is on the dependency of the Jar version.

# Initialize the project

Create an empty Spring Boot project

提示

You can use Spring Initializer (opens new window) to quickly initialize a Spring Boot project

# Add dependencies

Maven:

        <!-- Introduce dependencies for the latest version of easy-es -->
        <dependency>
            <groupId>org.dromara.easy-es</groupId>
            <artifactId>easy-es-boot-starter</artifactId>
            <!-- Here Latest Version refers to the latest version of the dependency, such as 2.0.0, which can be obtained from the image below -->
            <version>Latest Version</version>
        </dependency>

        <!-- exclude the built-in es dependency in springboot to prevent conflicts with the easy-es dependency -->
        <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.17.8</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.17.8</version>
        </dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

Gradle:

compile group: 'org.dromara.easy-es', name: 'easy-es-boot-starter', version: 'Latest Version'
1

# ✨ Latest Version Latest Version: Maven Central (opens new window)

# Configuration

In the application.yml configuration file add the relevant configuration that EasyEs must have.

easy-es:
  enable: true #default is true, if false then the framework is not enabled
  address : 127.0.0.1:9200 # es's connection address, must include the port If it is a cluster, it can be separated by a comma Example: 127.0.0.1:9200,127.0.0.2:9200
  username: elastic #If not, you can omit this line
  password: WG7WVmuNMtM4GwNYkyWH #If not, then this line can be omitted
1
2
3
4
5

Other configurations can be omitted for the time being, and there will be a section describing the configuration of EasyEs in detail later

Add the @EsMapperScan annotation to the Spring Boot startup class and scan the Mapper folder for.

@SpringBootApplication
@EsMapperScan("com.xpc.eases.sample.mapper")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
1
2
3
4
5
6
7
8
9

# Background

There is a Document document table. With the expansion of the data volume, its query efficiency can no longer meet the product requirements. The table structure is as follows. We plan to migrate the content of this table to the Es search engine to improve query efficiency.

id title content
primary key title content

# Coding

Write entity class Document.java (here we use Lombok (opens new window) to simplify the code)

@Data
@IndexName
public class Document {
    /**
     * Unique id in es
     */	
    private String id;
    /**
     * Document title
     */
    private String title;
    /**
     * Document content
     */
    private String content;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

提示

  • The above field names and underscores to auto-hump, field storage types in ES, separators, etc. are configurable and will be introduced in the next sections.
  • String type will be created by EE as keyword type by default, keyword type supports exact query, etc.
  • If you want to split the query, you can add the @IndexField annotation to the field and specify the field type as text, and specify the splitter, just like content above.

Write Mapper class DocumentMapper.java

public interface DocumentMapper extends BaseEsMapper<Document> {
}
1
2

##Preceding operations

Manually create an index (equivalent to a table in a database such as MySQL), with which subsequent CRUD operations can be carried out.

    @Test
    public void testCreateIndex() {
    // Test to create an index, and the framework will help you generate the index with one click according to the user-defined comments added on the entity classes and fields. Make sure that the index hosting mode is in manual mode (it is in this mode by default), and it will conflict if it is automatic.        boolean success = documentMapper.createIndex();
        Assertions.assertTrue(success);
    }
1
2
3
4
5

提示

-At present, we provide four ways to create indexes. The above demonstration is the one-click creation mode recommended for beginners. If you are interested in other centralized modes, you can go to the index hosting chapter to check it out. -The smooth mode of automatic transmission mode can automatically sense the index change, automatically adjust the index and smoothly migrate data, but it is not recommended for Xiaobai. It is recommended to use it after understanding the principle and source code. -Of course, you can also maintain the index through several other modes, or through tools such as logstash and es-head.

# Getting Started (CRUD)

Add a test class for functional testing.

Test Add: Add a new data (equivalent to Insert operation in MySQL)

    @Test
    public void testInsert() {
        // Test inserting data
        Document document = new Document();
        document.setTitle("Old man");
        document.setContent("push * technology is too hard");
        int successCount = documentMapper.insert(document);
        System.out.println(successCount);
    }
1
2
3
4
5
6
7
8
9

test query: query the specified data based on the conditions (equivalent to the Select operation in MySQL)

    @Test
    public void testSelect() {
        // test query write the same as MP can be chained, or not chained according to the use of flexible choice can be
        String title = "Old man";
        Document document = EsWrappers.lambdaChainQuery(documentMapper)
                 .eq(Document::getTitle, title)
                 .one();
        System.out.println(document);
}
1
2
3
4
5
6
7
8
9
Help us improve this document (opens new window)
Last update: 2025/02/05
Avoid pit
Springboot demo

← Avoid pit Springboot demo→

Theme by Vdoing | Copyright © 2021-2025 LaoHan | Zhejiang ICP No. 2022020479 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式