我试图连接到托管服务qbox上的群集,但出现与路径有关的错误。我不确定如何指定端点API。有任何想法吗?
public Map<String, Object> putJsonDocument(int partid, String partnumber){
Map<String, Object> jsonDocument = new HashMap<String, Object>();
jsonDocument.put("partid", partid);
jsonDocument.put("partnumber", partnumber);
return jsonDocument;
}
public void ESUpdate() {
org.elasticsearch.node.Node node = org.elasticsearch.node.NodeBuilder.nodeBuilder().node();
Client client = node.client();
client.prepareIndex("soogrindex", "searchrow", "1")
.setSource(putJsonDocument(1, "test55" )).execute().actionGet();
}
Exception in thread "main" java.lang.IllegalStateException: path.home is not configured
at org.elasticsearch.env.Environment.<init>(Environment.java:101)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:81)
at org.elasticsearch.node.Node.<init>(Node.java:128)
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:152)
at com.example.GetSoogrSitemap.ESUpdate(GetSoogrSitemap.java:708)
at com.example.GetSoogrSitemap.main(GetSoogrSitemap.java:2056)
最佳答案
使用NodeBuilder
,您只能连接到与程序在同一主机上运行的Elasticsearch服务器。看来您正在尝试从笔记本电脑或不在同一QBox主机上的其他主机连接到QBox上的群集。
您应该尝试构建一个TransportClient
,如下所示:
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("your.qbox.host"), 9300));