SpringBoot整合 ElasticSearch 的三种方式

SpringBoot整合 ElasticSearch 的三种方式

demo 1

通过es提供的elasticsearch-rest-high-level-clent API来整合【基于http协议】
1.搭建SpringBoot 工程
2.引入ES坐标


<dependency>
    <groupId>org.elasticsearch.clientgroupId>
    <artifactId>elasticsearch-rest-clientartifactId>
    <version>7.4.0version>
dependency>
<dependency>
    <groupId>org.elasticsearchgroupId>
    <artifactId>elasticsearchartifactId>
    <version>7.4.0version>
dependency>
<dependency>
    <groupId>org.elasticsearch.clientgroupId>
    <artifactId>elasticsearch-rest-high-level-clientartifactId>
    <version>7.4.0version>
dependency>

3.编写测试类

@RunWith(SpringRunner.class)
@SpringBootTest
public class EsQuickstartApplicationTests {

@Test
public void testA () throws Exception {
    RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
            new HttpHost(
                    "localhost",
                    9200,
                    "http"
            )
    ));
    System.out.println(client);
}
}

demo2:

通过es的 transport api来整合【基于socket协议,效率略快】

<dependency>
    <groupId>org.elasticsearch.clientgroupId>
    <artifactId>transportartifactId>
    <version>7.7.0version>
dependency>

demo3:

使用spring-data-elasticsearch 来整合

你可能感兴趣的:(ElasticSearch,spring,boot,es,elasticsearch)