elasticsearch报错解决办法:NoNodeAvailableException[None of the configured nodes are available

ES搭建完成后,使用localhost 和127.0.0.1都能正常访问和检索数据,但是使用服务器本机IP确报错。如下错误:

org.elasticsearch.client.transport.NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{GQyUuNepTJ -VZ7Sj -8cqcAHloca1host}{127.0.0.1:9300}]

 解决方法: 
  修改es配置文件(elasticsearch-2.3.3\config\elasticsearch.yml),
  修改network.host
  network.host:服务器IP地址

elasticsearch报错解决办法:NoNodeAvailableException[None of the configured nodes are available_第1张图片

elasticsearch报错解决办法:NoNodeAvailableException[None of the configured nodes are available_第2张图片

然后保存elasticsearch.yml,重启es,最后发现还是不行,然后看看是不是代码的问题

配置类:

package com.gkd.blog.config;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author :zhaoyijie(Aquarius_genius)水瓶座鬼才
 * @create :2020/1/25 13:01
 */
@Configuration
public class ESConfig {
    @Bean
    public TransportClient client() throws UnknownHostException {
        TransportAddress node=new TransportAddress(InetAddress.getByName("localhost"),9300);
        //集群名blog
        Settings settings = Settings.builder().put("cluster.name","blog").build();
        TransportClient client=new PreBuiltTransportClient(settings);
        //这里可以addTransportAddress(node)多个节点
        client.addTransportAddress(node);
        System.out.println(client);
        return client;
    }
}

如果你的java代码连接方式为上面的代码,要在配置文件中存在此结点。

如果我这里节点名为blog,

注意一下,cluster.name在es配置文件(elasticsearch-2.3.3\config\elasticsearch.yml)存在。如下图所示:

elasticsearch报错解决办法:NoNodeAvailableException[None of the configured nodes are available_第3张图片

elasticsearch报错解决办法:NoNodeAvailableException[None of the configured nodes are available_第4张图片

cluster.name的名字要在配置文件中存在,否则还会报上面的错误。

你可能感兴趣的:(笔记,elasticsearch)