这个在高版本中已经废弃,官方建议我们使用:High Level REST Client
@Configuration
public class ElasticsearchConfig {
/**
* localhost:9300 写在配置文件中就可以了
*/
@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;
}
}
但我在spring-boot.version
改为2.1.3.RELEASE
时,这两个结点有效,没有过时。