ElasticSearch Java API:NoNodeAvailableException:无节点可用 [英] ElasticSearch Java API:NoNodeAvailableException: No node available
问题描述
设置设置= ImmutableSettings.settingsBuilder()
.put(cluster.name, foxzen)
.put(node.name,yu)。build();
客户端客户端=新的TransportClient(设置)
.addTransportAddress(新的InetSocketTransportAddress(XXX.XXX.XXX.XXX,9200));
// XXX是我的服务器的IP地址
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();
}
我从我的电脑访问服务器
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你知道,为搜索
}
为什么使用Java API来获取错误? p>
编辑
有 elasticsearch.yml
############## ####################集群############################# ######
#集群名称标识您的集群进行自动发现。如果您在同一网络上运行
#个多个集群,请确保使用唯一的名称。
#
cluster.name:foxzen
####################### ############节点#####################################
#节点名称在启动时动态生成,所以您可以手动配置
#。您可以将此节点绑定到一个特定的名称:
#
node.name:yu
有些建议:
1 - 使用端口9300. [9300-9400]用于节点到节点的通信,[9200-9300]用于HTTP流量。
2 - 确保您使用的Java API版本与服务器上运行的弹性搜索的版本相匹配。 p>
3 - 确保集群的名称为 foxzen
(检查服务器上的elasticsearch.yml)。 p>
4 - 删除 put(node.name,yu)
,您没有加入群集一个节点,因为您使用 TransportClient
,即使您看到您的服务器节点名为 yu
,所以你在任何情况下都想要一个不同的节点名称。
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/
get this
{
"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"
}
Why get error by using Java API?
EDIT
There is the cluster and node part config of 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
Some suggestions:
1 - Use port 9300. [9300-9400] is for node-to-node communication, [9200-9300] is for HTTP traffic.
2 - Ensure the version of the Java API you are using matches the version of elasticsearch running on the server.
3 - Ensure that the name of your cluster is foxzen
(check the elasticsearch.yml on the server).
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屋!