0

我在 mysite.com:9300 上运行了 elasticsearch v 5.4.0,使用 x-pack 身份验证:

登录:我的登录

密码:我的密码

我有带有 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"
4

1 回答 1

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;
    }

摇篮依赖:

    compile group: 'org.elasticsearch.client', name: 'x-pack-transport', version: '5.4.0'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch'
于 2017-07-21T11:34:07.483 回答