How to configure elasticsearch 5

二次信任 提交于 2019-12-11 06:29:35

问题


How to configure elasticsearch 5 TransportClient.

Now TransportClient is abstract class. I found only PreBuiltTransportClient, this is the new way to configure elasticsearch Client ?


回答1:


Yes, you can find that in the official documentation for 5.0 as well

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

It is worth nothing that the PreBuiltTransportClient is pre-configured with the following modules:

  • Netty3
  • Netty4
  • Reindex
  • Percolator
  • Mustache

Also make sure that you have a dependency on the transport artifact:

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



回答2:


First download respective jar file and keep that in lib folder and add them to build path. You can follow below code to configure it:

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


来源:https://stackoverflow.com/questions/38883784/how-to-configure-elasticsearch-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!