简体   繁体   English

ElasticSearch客户端连接无法

[英]ElasticSearch client connection impossible

I am having problems with ElasticSearch Client. 我在使用ElasticSearch Client时遇到问题。

I have designed a Java application (to finish my developer studies) that manage different databases MySQL, mongoDb and ElasticSearch. 我设计了一个Java应用程序(以完成开发人员研究),该应用程序管理不同的数据库MySQL,mongoDb和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. 使用TransportClient,它可以在本地运行,但是在真实服务器上,它会带来NoNodeAvailableException,表明没有已配置的节点可用。 Have try a lot of things to make it work but it doesn't. 尝试了很多事情以使其起作用,但没有成功。

  • So i decide to try connect and request with REST. 因此,我决定尝试使用REST进行连接和请求。 Here is my code, and the error i got is not very detailed : it's a ConnectException. 这是我的代码,我得到的错误不是很详细:这是一个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 很多家伙

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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