Elasticsearch - NoNodeAvailableException

后端 未结 3 449
迷失自我
迷失自我 2020-12-19 02:17

I get the following error when trying to connect to Elasticsearch 2 using the Java API for ES 2. This is the code:

Settings settings = Settings.settingsBuild         


        
相关标签:
3条回答
  • 2020-12-19 02:38

    The problem might be in the settings that you are using.

    Instead of creating the Client in these three steps:

    TransportClient transportClient = TransportClient.builder().settings(settings).build();
    Client c = null;
    try {
     c = transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(Receptor.es_ip), 9300));
    } catch (UnknownHostException e) {
     System.err.println(Util.getTimestampStr() + "UnknownHostException error.");
     e.printStackTrace();
    }
    

    Try creating it like this:

    Client client = new TransportClient()
                .addTransportAddress(new InetSocketTransportAddress(
                        InetAddress.getByName(Receptor.es_ip),
                        9300));
    

    If you want more data check this old answer to a similar question: Elastic search problems

    0 讨论(0)
  • 2020-12-19 02:46

    This problem could due to the network problem, if you are using network.host: _site_ in elasticsearch.yml AND sniffed TransportClient connection, i.e. multiple site-local addresses are available within the machine hosting es node.

    If you disable the sniff configuration, and the NoNodeAvailableException disappears, then you should double check the network configuration.

    Get the nodes stat

    GET /_nodes
    

    and check in the result to find transport configuration, i.e.

    "transport": {
        "bound_address": [
          "192.168.1.84:9300",
          "172.29.0.1:9300"
        ],
        "publish_address": "172.29.0.1:9300",
        "profiles": {}
      },
    

    If there are multiple site-local addresses, the network.publish_host that sniffed TransportClient will connect to, might be an unexpected address, because

    If not specified, this defaults to the “best” address from network.host, sorted by IPv4/IPv6 stack preference, then by reachability.

    To solve it, simple specify the network.publish_host

    network.publish_host: $DESIRED_IP_ADDRESS

    in elasticsearch.yml.

    0 讨论(0)
  • 2020-12-19 02:50

    @AndreiStefan gave the solution to my problem thanks to the post he linked. The solution was as straightforward as:

    network.bind_host: 0
    

    Thank you guys.

    0 讨论(0)
提交回复
热议问题