简体   繁体   中英

ElasticSearch client connection impossible

I am having problems with ElasticSearch Client.

I have designed a Java application (to finish my developer studies) that manage different databases MySQL, mongoDb and ElasticSearch. I was able to read, create and update data from a db to another. All was designed and coded with local databases and everything works very well. All the tests have been validated so we decide to make it work on distant servers on the real databases.

And then the problems begin to happened, and especially the one i'm stuck with since two long days and i'm getting really desperate.

  • With TransportClient it worked on local, but on real server it bring a NoNodeAvailableException saying that none of the configured nodes are available. Have try a lot of things to make it work but it doesn't.

  • So i decide to try connect and request with REST. Here is my code, and the error i got is not very detailed : it's a ConnectException.

Code :

    // Get the connection client from ES database
    public static RestHighLevelClient getConnection()
    {
        // Singleton
        if(client == null)
        {
            try             
            {       
                // Set Credz
                final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("Login", "pwd"));             

                // Builder
                RestClientBuilder builder = RestClient.builder(new HttpHost("ServerIP", 9200, "http")).setHttpClientConfigCallback(new HttpClientConfigCallback() 
                {
                    @Override
                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) 
                    {   
                        System.out.println("Setting taken !");
                        return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                    }
                });                 

                // Create client
                client = new RestHighLevelClient (builder);

                ClusterHealthRequest healthReq = new ClusterHealthRequest("looppy-cluster");
                ClusterHealthResponse response = client.cluster().health(healthReq, RequestOptions.DEFAULT);
    int numberOfNodes = response.getNumberOfNodes(); 
            System.out.println("Nodes Nb : " + numberOfNodes);

            } 
            catch(Exception ex)
            {   
System.out.println("Client connection problem");
                ex.printStackTrace();
            }
        }       

        return client;
    }   

And here is the exception i got :

    java.net.ConnectException
    at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227)
    at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1256)
    at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1231)
    at org.elasticsearch.client.ClusterClient.health(ClusterClient.java:146)
    at utils.ElasticSearchMng.getConnection(ElasticSearchMng.java:86)
    at utils.ElasticSearchMng.getLoopiesFromES(ElasticSearchMng.java:133)
    at program.Program$1.run(Program.java:96)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.ConnectException
    at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:168)
    at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:561)
    at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:822)
    at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:192)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
    at java.lang.Thread.run(Unknown Source)

I'm getting despered and ireally don't understand what's happening, would appreciate a lot if someone can help !

thx a lot guyz

问题终于解决了,端口不是一个好端口,与服务器一起工作的人们告诉我该端口,因为他们更改了该端口并且它直接起作用了;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM