Can't connect to ElasticSearch server using Java API

后端 未结 4 922
醉梦人生
醉梦人生 2020-12-29 05:22

I am trying to connect to an ElasticSearch server using the Java API. I using elasticsearch service to start/stop and elasticsearch head for visualising the cluster. The clu

4条回答
  •  Happy的楠姐
    2020-12-29 05:39

    First, version is really important, Java API is strong related with the version you are using,

    This solution works in elasticSearch v 5.4.1 with java 8

    make sure that you are getting all dependencies, and the child dependencies (not only elasticSearch jar), use maven, ivy etc for getting the dependencies tree.

    in ivy for example :

     
      
    

    //--------------------- then in a class you can call:

     TransportClient client;
    
        client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    

提交回复
热议问题