ElasticSearch Java API:NoNodeAvailableException: 无可用节点 [英] ElasticSearch Java API:NoNodeAvailableException: No node available

查看:22
本文介绍了ElasticSearch Java API:NoNodeAvailableException: 无可用节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static void main(String[] args) throws IOException {
    Settings settings = ImmutableSettings.settingsBuilder()
            .put("cluster.name", "foxzen")
            .put("node.name", "yu").build();
    Client client = new TransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9200));
            // XXX is my server's ip address
    IndexResponse response = client.prepareIndex("twitter", "tweet")
            .setSource(XContentFactory.jsonBuilder()
                    .startObject()
                    .field("productId", "1")
                    .field("productName", "XXX").endObject()).execute().actionGet();
    System.out.println(response.getIndex());
    System.out.println(response.getType());
    System.out.println(response.getVersion());
    client.close();
}

我从我的电脑访问服务器

I access server from my computer

curl -get http://XXX.XXX.XXX.XXX:9200/

得到这个

{
    "status" : 200,
    "name" : "yu",
    "version" : {
        "number" : "1.1.0",
        "build_hash" : "2181e113dea80b4a9e31e58e9686658a2d46e363",
        "build_timestamp" : "2014-03-25T15:59:51Z",
        "build_snapshot" : false,
        "lucene_version" : "4.7"
    },
    "tagline" : "You Know, for Search"
}

为什么使用 Java API 会出错?

Why get error by using Java API?

编辑

elasticsearch.yml

################################### Cluster ###################################

# Cluster name identifies your cluster for auto-discovery. If you're running
# multiple clusters on the same network, make sure you're using unique names.
#
cluster.name: foxzen


#################################### Node #####################################

# Node names are generated dynamically on startup, so you're relieved
# from configuring them manually. You can tie this node to a specific name:
#
node.name: yu

推荐答案

一些建议:

1 - 使用端口 9300.[9300-9400] 用于节点到节点通信,[9200-9300] 用于 HTTP 流量.

1 - Use port 9300. [9300-9400] is for node-to-node communication, [9200-9300] is for HTTP traffic.

2 - 确保您使用的 Java API 版本与服务器上运行的 elasticsearch 版本相匹配.

2 - Ensure the version of the Java API you are using matches the version of elasticsearch running on the server.

3 - 确保您的集群名称为 foxzen(检查服务器上的 elasticsearch.yml).

3 - Ensure that the name of your cluster is foxzen (check the elasticsearch.yml on the server).

4 - 删除 put("node.name", "yu"),因为您使用的是 TransportClient,所以您没有作为节点加入集群,即使您是这样,您的服务器节点似乎被命名为 yu,因此无论如何您都需要一个不同的节点名称.

4 - Remove put("node.name", "yu"), you aren't joining the cluster as a node since you are using the TransportClient, and even if you were it appears your server node is named yu so you would want a different node name in any case.

这篇关于ElasticSearch Java API:NoNodeAvailableException: 无可用节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆