Elasticsearch and connections to QBOX Error

房东的猫 提交于 2020-01-17 06:15:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!