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
    • 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
      • Introduction
      • Use posture
      • Expand
    • 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
  • Core function
LaoHan
2024-01-21
目录

Multiple data sources support

# Introduction

We provide the same multi-data source support as MP, with basically no additional learning and understanding costs. If you have been exposed to MP's multi-data sources before, you can simply understand and use it here. What needs special attention is that, We have adopted a more lightweight solution, which does not require the introduction of multi-data source plug-ins before use like MP. It can be directly configured and used, which is more convenient to use. In addition, considering that MP uses the @DS (*Silk) annotation, in order to distinguish it from MP, adjust the annotation to @EsDS (Russian is *Silk) in EasyEs.

# Use posture

Step 1: Add multiple data source related configurations to the configuration file

easy-es:
   dynamic:
     datasource:
       ds1:
         address: 10.20.64.228:9200 #Connection address of data source 1
         #username: 'Remove this line if there is nothing'
         #password: 'Remove this line if there is nothing'
       ds2:
         address: 49.234.28.111:9200 #Connection address of data source 2
         #username: 'Remove this line if there is nothing'
         #password: 'Remove this line if there is nothing'
       #dsn…
1
2
3
4
5
6
7
8
9
10
11
12

Step 2: Add the @EsDS annotation to the corresponding Mapper

Add the @EsDS annotation to the Mapper involved, and specify the data source name in the value. The data source name is ds1, ds2... added in the configuration file above. Of course, you can also call it dds, xds... In short, you The desired connection address and the value in the annotation can match.

@EsDS("ds1")
public interface DocumentMapper extends BaseEsMapper<Document> {
}

@EsDS("ds2")
public interface CommentMapper extends BaseEsMapper<Comment> {
}
1
2
3
4
5
6
7

Step 3: Inject the corresponding mapper for query

This step is relatively simple. Just use it as an ordinary mapper. However, compared with the previous mapper, each mapper is bound to a specific data source. After that, a series of CRUD operations performed through the mapper are specified by annotations. data source.

# Expand

Since the current version of EE does not provide an xml method similar to MP (dsl may not be suitable for expression in xml, and is still being explored), it uses a multi-dimensional hybrid query mode out of the box to meet the needs of all scenarios. Therefore, the @EsDS annotation cannot be added to the specific method, but it does not affect the user's use at all. Even if a very flexible scenario occurs, the user can still use a hybrid query to solve it. Entrust the mapper to complete CRUD. The data source specified by @EsDS on the mapper is the corresponding data source for hybrid query. Of course, you can also have other extremely flexible options, such as the following, directly get the framework assembled Use RestHighLevelClient.

public class DsTest{
     @Autowired
     private RestHighLevelClientUtils restHighLevelClientUtils;
    
     @Test
     public void testDs(){
         // Get the corresponding RestHighLevelClient by passing in restHighLevelClientId. RestHighLevelClientId is the data source name ds1, ds2... configured in the configuration file.
         RestHighLevelClient restHighLevelClient = restHighLevelClientUtils.getClient(String restHighLevelClientId);
        
         // After getting the corresponding RestHighLevelClient, I don’t need to tell you how to do the rest. It is the usage of ES native RestHighLevelClient. I don’t know how to use Baidu or look at the es official website.
     }
}

1
2
3
4
5
6
7
8
9
10
11
12
13

Compared with the above method, the out-of-box queries and hybrid queries provided by EE are obviously the best solutions and can help you minimize the amount of code. If you need to specify a specified index to query a certain data source, You can move to the chapter to see dynamic index support!

Help us improve this document (opens new window)
Last update: 2024/03/29
Data CRUD
Dynamic indexing support

← Data CRUD Dynamic indexing support→

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