daiqw 2019-08-22 14:56 采纳率: 100%
浏览 2897
已采纳

springboot整合elasticsearch提示org.elasticsearch.transport.NodeDisconnectedException


org.springframework.boot
spring-boot-starter-data-elasticsearch
2.1.4.RELEASE


org.springframework.data
spring-data-elasticsearch
2.1.4.RELEASE


org.elasticsearch
elasticsearch
2.4.0


org.elasticsearch.plugin
transport-netty4-client
6.4.0


org.elasticsearch.client
transport
6.4.0

    application.yml 配置如下:
        spring: 
              data:
elasticsearch:
  cluster-nodes: 192.168.100.21:9300,192.168.100.22:9300,192.168.100.23:9300
  cluster-name: wt
  repositories:
    enabled: true

         springboot版本1.5.8,linux安装ES版本是6.4.0,上面是工程里引入的jar,ES在浏览器能访问,且有数据,但是项目启动就连接不上

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{192.168.100.21}{192.168.100.21:9300}, {#transport#-2}{192.168.100.22}{192.168.100.22:9300}, {#transport#-3}{192.168.100.23}{192.168.100.23:9300}]
]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)
at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)

  • 写回答

1条回答 默认 最新

  • Amo_lt 2019-08-23 14:02
    关注

    在client初始化中,设置cluster_name,然后就可以了,正确的代码如下:

    + Settings settings = Settings.builder().put("cluster.name", "wt").build();
    Client client = TransportClient.builder()
                    .settings(settings)
                    .build().addTransportAddress(
                    new InetSocketTransportAddress(
                    InetAddress.getByName("127.0.0.1"), 9300)); //IP改成对应的
    

    或者:

     Settings settings = Settings.builder().put("cluster.name", SpringPropertiesUtil.getProperty("cluster.name")). 
                                            put("client.transport.ping_timeout",SpringPropertiesUtil.getProperty("elastic.ping.timeout")). 
                                            put("client.transport.nodes_sampler_interval",SpringPropertiesUtil.getProperty("elastic.sampler.interval")). 
                                            put("client.transport.sniff", true). 
                                            put("node.name",SpringPropertiesUtil.getProperty("search.node.name")).build(); 
    
    
    
    client = new PreBuiltTransportClient(settings) 
                                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(getIndexHostName()), getIndexPort())); 
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费