searchbox-io / Jest

Elasticsearch Java Rest Client.
Apache License 2.0
2.11k stars 727 forks source link

autodiscovery #618

Open cumtwwei opened 6 years ago

cumtwwei commented 6 years ago

try to use autodiscovery, but got some error. Thanks a lot!

My code: JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig( new HttpClientConfig .Builder(hostLst) .credentialsProvider(customCredentialsProvider) .multiThreaded(true) defaultMaxTotalConnectionPerRoute .defaultMaxTotalConnectionPerRoute(Integer.parseInt(PropertyUtil.getProperty("es.defaultMaxTotalConnectionPerRoute", "2"))) .maxTotalConnection(Integer.parseInt(PropertyUtil.getProperty("es.maxTotalConnection", "20"))) .connTimeout(Integer.parseInt(PropertyUtil.getProperty("es.connTimeout", "10000"))) .readTimeout(Integer.parseInt(PropertyUtil.getProperty("es.readTimeout", "10000"))) .discoveryEnabled(Boolean.parseBoolean(PropertyUtil.getProperty("es.discoveryEnabled", "true"))) .discoveryFrequency(Long.parseLong(PropertyUtil.getProperty("es.discoveryFrequency", "1000")), TimeUnit.MILLISECONDS) .maxConnectionIdleTime(Long.parseLong(PropertyUtil.getProperty("es.maxConnectionIdleTime", "1500")), TimeUnit.MILLISECONDS) .gson(new GsonBuilder() .setDateFormat("yyyy-MM-dd HH:mm:ss") .create()) .build() ); client = factory.getObject();

but get the error below: 018-09-26 17:49:45 [NodeChecker RUNNING] INFO AbstractJestClient:60 - Setting server pool to a list of 1 servers: [http://127.0.0.1:9200] io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://127.0.0.1:9200 at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:73) at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:63) at com.rj.udap.elasticsearchtools.service.impl.KpiServiceImpl.search(KpiServiceImpl.java:65) at com.rj.udap.elasticsearchtools.MyTest.search(MyTest.java:138) at com.rj.udap.elasticsearchtools.MyTest.main(MyTest.java:63) Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:9200 [/127.0.0.1] failed: Connection refused (Connection refused) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) at io.searchbox.client.http.JestHttpClient.executeRequest(JestHttpClient.java:136) at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:70) ... 4 more Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ... 15 more java.lang.NullPointerException at com.rj.udap.elasticsearchtools.MyTest.search(MyTest.java:139) at com.rj.udap.elasticsearchtools.MyTest.main(MyTest.java:63)

cumtwwei commented 6 years ago

i have set the hosts info to hostLst, but the log seem like try to connnect 127.0.0.1 the hosts info i config: es.hosts=admin:123456@10.211.55.6:8080