spring-data-elasticsearch cluster-nodes和cluster-name配置过时Deprecated?
匿名 提问于:2019-12-04
1 0

springboot集成elasticsearch,配置文件如下

idea提示已经过时了,请问该怎么写?

  • 所有回答
xingfu2017 回答于:2020-04-02
1 0

这个在高版本中已经废弃,官方建议我们使用:High Level REST Client

 @Configuration
public class EsConf {
 
 	//localhost:9200 写在配置文件中就可以了
    @Bean
    RestHighLevelClient elasticsearchClient() {
        ClientConfiguration configuration = ClientConfiguration.builder()
                .connectedTo("localhost:9200")
  		//.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;
    }
 
}

ElasticsearchTemplate改为ElasticsearchRestTemplate
参考api:ElasticsearchRestTemplate

也可以使用Bboss框架

https://esdoc.bbossgroups.com/#/?id=%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e7%9a%84-orm-%e5%ba%93-elasticsearch-bboss

kakawade 回答于:2020-03-17
1 0

请问这个问题解决了吗?

loonbs 回答于:2019-12-11
1 0
@Configuration
public class EsConf {

    @Bean
    RestHighLevelClient elasticsearchClient() {
        ClientConfiguration configuration = ClientConfiguration.builder()
                .connectedTo("localhost:9200")
                .build();
        RestHighLevelClient client = RestClients.create(configuration).rest();

        return client;
    }

}
我来回答    spring-data-elasticsearch cluster-nodes和cluster-name配置过时Deprecated?