# New Java API with Credentials and SSL certificates

**URL:** <https://discuss.elastic.co/t/new-java-api-with-credentials-and-ssl-certificates/301173>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 31, 2022, 9:44am UTC](https://discuss.elastic.co/t/new-java-api-with-credentials-and-ssl-certificates/301173 "2022-03-31T09:44:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [March 31, 2022, 9:44am UTC](https://discuss.elastic.co/t/new-java-api-with-credentials-and-ssl-certificates/301173/1 "2022-03-31T09:44:14Z")

</div>

To connect to new Java API, this url:

[https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/8.1/connecting.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/8.1/connecting.html)

explains to do this :

```auto
// Create the low-level client
RestClient restClient = RestClient.builder(
    new HttpHost("localhost", 9200)).build();

// Create the transport with a Jackson mapper
ElasticsearchTransport transport = new RestClientTransport(
    restClient, new JacksonJsonpMapper());

// And create the API client
ElasticsearchClient client = new ElasticsearchClient(transport);

```

I guess that this example is on an unsecured cluster. bad ! bad ! bad! 😉

From ES 8, It is mandatory to have clusters being secured with SSL dialog certificate: **elastic-certificates.p12** and **elastic-stack-ca.p12**

Could you provide, please, a code snippet to show humanity **How to connect to ES8, using Java API 8.1 and providing Credentials + SSL certificates**

This would be very helpful, waiting for the official documentation.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 31, 2022, 10:30am UTC](https://discuss.elastic.co/t/new-java-api-with-credentials-and-ssl-certificates/301173/2 "2022-03-31T10:30:18Z")

</div>

Hey,

There is a paragraph in the RestClient documentation: [Encrypted communication | Elasticsearch Java API Client [8.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/8.1/_encrypted_communication.html)

There is also a blog post showing how to set this up, using testcontainers, where you can probably still some code snippets: [Running Elasticsearch 8.0 with Testcontainers](https://spinscale.de/posts/2022-02-17-running-elasticsearch-8-with-testcontainers.html)

hope this helps!

---

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [March 31, 2022, 11:33am UTC](https://discuss.elastic.co/t/new-java-api-with-credentials-and-ssl-certificates/301173/3 "2022-03-31T11:33:55Z")

</div>

OK, I did not make the link between what was kept from **Java Low Level REST** and new **Java API**.

Frankly, I am so confused and lost in the new Java API that I do not recollate everything.

Thanks for the explanations.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 28, 2022, 11:34am UTC](https://discuss.elastic.co/t/new-java-api-with-credentials-and-ssl-certificates/301173/4 "2022-04-28T11:34:02Z")

</div>

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