如何配置elasticsearch 5

时间:2016-08-10 21:21:31

标签: elasticsearch spring-data-elasticsearch

如何配置elasticsearch 5 TransportClient。

现在TransportClient是抽象类。我发现只有PreBuiltTransportClient,这是配置elasticsearch Client的新方法吗?

2 个答案:

答案 0 :(得分:2)

是的,您也可以在official documentation for 5.0中找到

Settings settings = Settings.builder()
   .put("cluster.name", "ElasticSearchClusterName");

TransportClient client = new PreBuiltTransportClient(settings)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));

使用以下模块PreBuiltTransportClientpre-configured是没有价值的:

  • Netty3
  • Netty4
  • 重新索引
  • 渗滤器

还要确保您对transport工件具有依赖性:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.0.0-beta1</version>
</dependency>

答案 1 :(得分:0)

首先下载相应的jar文件并将其保存在lib文件夹中,然后将它们添加到构建路径中。 您可以按照以下代码进行配置:

 Settings settings = Settings.builder()
    .put("cluster.name", "ElasticSearchClusterName")
    //.put("client.transport.sniff", true)
    //.put("shield.user", elasticUserName+":"+elasticPassword)
    .build();

TransportClient client = new PreBuiltTransportClient(settings)
                                  .addTransportAddress(new InetSocketTransportAddress(elasticHostOne, elasticTransportPort))
                                  .addTransportAddress(new InetSocketTransportAddress(elasticHostTwo, elasticTransportPort))
                                  .addTransportAddress(new InetSocketTransportAddress(elasticHostThree, elasticTransportPort));