0

i am trying to invoke rest call and have below rest high level client.

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("elastic", "cool"));
        client = new RestHighLevelClient(RestClient.builder(new HttpHost(HOST, PORT, SCHEMA))
                .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                    @Override
                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                        return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                    }
                }));

i have host and port defined in application.properties file as below

#test/dev host elastic service url 
HOST.URL=http://go-test

#test/dev host port 
HOST.PORT=9200
  
SCHEMA=http

 

My bean property

@Value("${HOST.URL}")
private String HOST;

@Value("${HOST.PORT}")
private int PORT;

@Value("${SCHEMA}")
private String SCHEMA;

when i try to run i am getting below execption...

Caused by: java.net.UnknownHostException: http://go-test
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1255)
    at java.net.InetAddress.getAllByName(InetAddress.java:1171)
    at java.net.InetAddress.getAllByName(InetAddress.java:1105)

dont know what is causing the issue, when i try with ip, it is working perfectly. Same host name when i try in chrome browser, it is working fine.. getting response from bacekend rest api..

{
  "name" : "ip",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "q",
  "version" : {
    "number" : "7.9.3",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "c",
    "build_date" : "2020-10-16T10:36:16.141335Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
5
  • Are you sure the host url should be http:/go-test and not http://go-test? Commented Aug 18, 2021 at 5:10
  • HOST.URL=http:/go-test should HOST.URL=http://go-test. Commented Aug 18, 2021 at 5:10
  • You are not showing how your properties are mapped to the values you pass to the HttpHost constructor, but from the error message HOST.URL should just be the host name. Commented Aug 18, 2021 at 5:45
  • sorry it was typo.. url is http:// go-test Commented Aug 18, 2021 at 5:47
  • can do a ping to go-test from your machine? its not working and you know the ip address of the host then make a entry in the hosts file. Commented Aug 18, 2021 at 6:19

1 Answer 1

1

This code is passing a URL to code that is expecting only a hostname.

Set HOST to go-test instead of http://go-test.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you edit the question then to reflect what you're trying now and the error that you're getting. If it's still UnknownHostException then that must be the wrong hostname.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.