Elasticsearch High Rest Client

I am new to writing the Client for ES , some how i was able to figure out to write basic client in java, can some one help me out how to pass credentials and self signed certificates

private static class RestHighLevelClientHelper {
	private static final RestHighLevelClient CLIENT = new RestHighLevelClient(
			RestClient.builder(
					new HttpHost("localhost", 9200, "http"),
					new HttpHost("localhost", 9201, "http")));
}


public static RestHighLevelClient getElasticSearchClientInstance() {
	return RestHighLevelClientHelper.CLIENT;
}

Start here: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html

Hi,
I have a similar issue connecting to elastic cloud. I followed the instructions how to set high-level client.
The problem i have is "Connection reset by peer". Could you help me with this issue? I tried to search online about how to connect to elastic cloud, but I failed to find any. Thank you.

Code below does work with regular ES node I installed on ami linux image.

Code:
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("username", "password"));

    RestClientBuilder builder = RestClient.builder(new HttpHost("clusterId.us-east-1.aws.found.io", 9243));
    lowRestClient = builder.build();
    highLevelClient = new RestHighLevelClient(builder);
   CreateIndexRequest request = new CreateIndexRequest("index-abc");
   CreateIndexResponse createIndexResponse = highLevelClient.indices().create(request);

Exception in thread "main" java.io.IOException: Connection reset by peer
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:728)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:198)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:522)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:508)
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:99)

1 Like

@Mingchih_Lin It would be better to open your own question as it's a different problem.
Will be easier for other users to find it IMO. Also, would be lovely if you format your code to make it nicer to read. (See https://discuss.elastic.co/c/elasticsearch)

Anyway, you need probably to change:

RestClientBuilder builder = RestClient.builder(new HttpHost("clusterId.us-east-1.aws.found.io", 9243));

to

RestClientBuilder builder = RestClient.builder(new HttpHost("clusterId.us-east-1.aws.found.io", 9243, "https"));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.