博主
258
258
258
258
专辑

第十五节 SPRING.DATA.ELASTICSEARCH.CLUSTER-NODES、CLUSTER-NAME过期问题

亮子 2022-11-23 01:09:40 3493 0 0 0

(1) 这个在高版本中已经废弃,如果要继续使用请将spring-boot.version改为2.1.3.RELEASE时,这两个结点有效,没有过时。
(2) 这个在高版本中已经废弃,官方建议我们使用:High Level REST Client

图片alt

  • 增加下面配置类
@Configuration
public class ElasticsearchConfig {
    @Bean
    RestHighLevelClient elasticsearchClient() {
        ClientConfiguration configuration = ClientConfiguration.builder()
                .connectedTo("localhost:9300")
                //.withConnectTimeout(Duration.ofSeconds(5))
                //.withSocketTimeout(Duration.ofSeconds(3))
                //.useSsl()
                //.withDefaultHeaders(defaultHeaders)
                //.withBasicAuth(username, password)
                // ... other options
                .build();
        RestHighLevelClient client = RestClients.create(configuration).rest();
        return client;
    }
}

参考文章