SpringBoot集成ES

in ELK with 0 comment

导入依赖

配置jdk

Java编译版本

JavaScript规范

依赖版本问题

==问题:默认的版本和我们使用的ES版本不一致==

==解决:版本自定义==

注入RestHighLevelClient

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//spring两个步骤:
//1、找对象
//2、放到spring中待用
//3、如果是SpringBoot 就分析源码
// xxxAutoConfiguration xxxProperties

@Configuration //xml
public class ElasticSearchClientConfig {

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

springboot源码中提供对象

Responses