[英]ElasticSearch client connection impossible
我在使用ElasticSearch Client時遇到問題。
我設計了一個Java應用程序(以完成開發人員研究),該應用程序管理不同的數據庫MySQL,mongoDb和ElasticSearch。 我能夠讀取,創建並將數據庫中的數據更新到另一個數據庫。 所有內容均使用本地數據庫進行設計和編碼,並且一切正常。 所有測試均已通過驗證,因此我們決定使其在實際數據庫上的遠程服務器上運行。
然后問題開始發生,尤其是自從兩天以來一直困擾我的問題,我變得非常絕望。
使用TransportClient,它可以在本地運行,但是在真實服務器上,它會帶來NoNodeAvailableException,表明沒有已配置的節點可用。 嘗試了很多事情以使其起作用,但沒有成功。
因此,我決定嘗試使用REST進行連接和請求。 這是我的代碼,我得到的錯誤不是很詳細:這是一個ConnectException。
代碼:
// 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;
}
這是我得到的例外:
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)
我感到非常絕望,並且很不了解所發生的事情,如果有人可以幫助我將不勝感激!
很多家伙
問題終於解決了,端口不是一個好端口,與服務器一起工作的人們告訴我該端口,因為他們更改了該端口並且它直接起作用了;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.