问题
I am trying to connect to a cluster on qbox the hosting service and I get an error relating to path. I am unsure how to specify the endpoint API. Has anyone any ideas?
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)
回答1:
Using NodeBuilder
you can only connect to an Elasticsearch server running on the same host as your program. It seems you're trying to connect to a cluster on QBox from your laptop or another host not located on the same QBox host.
You should try building a TransportClient
instead, like this:
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("your.qbox.host"), 9300));
来源:https://stackoverflow.com/questions/35355957/elasticsearch-and-connections-to-qbox-error