首页 > 编程语言 > 详细

springboot集成elasticsearch

时间:2020-04-19 22:49:35      阅读:54      评论:0      收藏:0      [点我收藏+]

版本信息

springboot集成es会有版本要求。
springboot:2.2.6
es:6.4.0

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

有三种方式:

百度查得:
Spring Boot更新到2.x版本, 默认spring-boot-starter-data-elasticsearch 默认的ES版本为5.6.9;如果你仍然使用Spring Boot 1.x版本,那么默认的Elastisearch版本为2.x ( https://www.jianshu.com/p/c5c3e834c028

spring官网
https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.RC3/reference/html/#preface.versions
技术分享图片

high-level-client

pom添加依赖

 <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>6.4.3</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.4.3</version>
        </dependency>

需要一个 RestClient 的 bean,在application里添加或者用 @Component

public class TiebaApplication {

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

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("192.168.2.202", 9200, "http")));
        return client;
    }

    @Bean
    public ExecutorService pool(){
        ExecutorService pool =  Executors.newFixedThreadPool(10);
        return pool;
    }

}

使用(官网api: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.4/java-rest-high.html

springboot集成elasticsearch

原文:https://www.cnblogs.com/l1057618497/p/12733534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!