Background:

In actual development, for some real-time requirements that are not high and require some aggregated data queries, Elasticsearch is generally used. Its advantages are high query efficiency and the ability to store large amounts of data.We use AWS opensearch in our actual project. In fact, opensearch is also a branch of Elasticsearch, and the built-in Elasticsearch is also Elasticsearch. Next, I will integrate it according to opensearch

Steps to integrate OpenSearch in springboot:

  1. Add pom dependency:
    The OpenSearch version is set according to the actual springBoot version and the ES service version
    1
    2

  2. Add basic configuration
    The basic information includes the host address of the ES connection, username and password, SSL, timeout, keep-alive strategy and other information. Of course, this is only part of it. For more information, please refer to the official website for more configurations.
    3
    4
    5
    6

  3. ES read-write separation configuration
    7
    Configure the jpa package path that needs to be scanned, and rewrite OpenSearchRestTemplate

  4. use
    8
    Just use it like you would use JPA