Hi, everyone.
I am using the Elasticsearch High Level REST client
to access the service, but I am getting an error Name or service not known
. However, I can successfully access the service using curl. Since I upgraded from an older version to 7.17 and I am using the Rest High Client as a transitional solution, I'm encountering this strange issue and I'm unsure how to resolve it.
Thank you
JDK 17
SpringBoot 3.1.2
elasticsearch 7.17.12
elasticsearch-rest-high-level-client 7.17.12
error :
java.net.UnknownHostException: http://127.0.0.1:9200: Name or service not known
at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:934) ~[na:na]
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1543) ~[na:na]
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:852) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1533) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1385) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1306) ~[na:na]
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) ~[httpclient-4.5.13.jar!/:4.5.13]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:666) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:637) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:472) ~[httpcore-nio-4.4.16.jar!/:4.4.16]
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:280) ~[httpcore-nio-4.4.16.jar!/:4.4.16]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:295) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:381) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:130) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.execute(CloseableHttpAsyncClientBase.java:116) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:138) ~[httpasyncclient-4.1.5.jar!/:4.1.5]
at org.elasticsearch.client.RestClient.lambda$performRequestAsync$0(RestClient.java:393) ~[elasticsearch-rest-client-8.7.1.jar!/:8.7.1]
at org.elasticsearch.client.Cancellable$RequestCancellable.runIfNotCancelled(Cancellable.java:90) ~[elasticsearch-rest-client-8.7.1.jar!/:8.7.1]
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:391) ~[elasticsearch-rest-client-8.7.1.jar!/:8.7.1]
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:378) ~[elasticsearch-rest-client-8.7.1.jar!/:8.7.1]
at org.elasticsearch.client.RestHighLevelClient.getVersionValidationFuture(RestHighLevelClient.java:2735) ~[elasticsearch-rest-high-level-client-7.17.12.jar!/:8.7.1]
at org.elasticsearch.client.RestHighLevelClient.performClientRequest(RestHighLevelClient.java:2692) ~[elasticsearch-rest-high-level-client-7.17.12.jar!/:8.7.1]
..........
java config:
@Autowired
private ElasticsearchProperties elasticsearchProperties;
@Bean
public RestHighLevelClient restHighLevelClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials(
elasticsearchProperties.getUsername(), elasticsearchProperties.getPassword()
)
);
return new RestHighLevelClient(
RestClient.builder(
new HttpHost("http://" + elasticsearchProperties.getUris().get(0))
)
.setHttpClientConfigCallback(
httpAsyncClientBuilder ->
httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
)
);
}
application.yml:
spring:
elasticsearch:
uris: 127.0.0.1:9200
username: elastic
password: 123123123123
Thank you