我在mysite.com:9300上运行了elasticsearch v 5.4.0, 使用x-pack auth:
登录:mylogin
密码:mypassword
我有使用Spring Data Elasticsearch v 3.0.0.M4的java + kotlin应用程序:
compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.0.0.M4'
有没有办法创建application.yml来连接elasticsearch?
我只找到elasticsearch-2.4.4版本的示例:
spring:
data:
elasticsearch:
cluster-nodes: mysite.com:9300
properties:
shield:
user: "mylogin:mypassword"
答案 0 :(得分:0)
在官方文档中,他们建议使用JavaConfig:
@Bean
public TransportClient elasticsearchClient() throws UnknownHostException {
TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
.put("client.transport.nodes_sampler_interval", "5s")
.put("client.transport.sniff", false)
.put("transport.tcp.compress", true)
.put("request.headers.X-Found-Cluster", "myclustername")
.put("xpack.security.transport.ssl.enabled", false)
.put("cluster.name", "myclustername")
.put("xpack.security.user", "mylogin:mypassword")
.build())
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("mysite.com"), 9300));
return client;
}
Gradle依赖项:
compile group: 'org.elasticsearch.client', name: 'x-pack-transport', version: '5.4.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch'