# How to connect ES8.8 through TCP port & certificate in java?

**URL:** <https://discuss.elastic.co/t/how-to-connect-es8-8-through-tcp-port-certificate-in-java/336793>\
**Category:** Elasticsearch\
**Created:** [June 23, 2023, 6:49pm UTC](https://discuss.elastic.co/t/how-to-connect-es8-8-through-tcp-port-certificate-in-java/336793 "2023-06-23T18:49:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jignesh\_Soni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jignesh_soni/32/87184_2.png) [@Jignesh\_Soni](https://discuss.elastic.co/u/Jignesh_Soni)\
**Post date:** [June 23, 2023, 6:49pm UTC](https://discuss.elastic.co/t/how-to-connect-es8-8-through-tcp-port-certificate-in-java/336793/1 "2023-06-23T18:49:46Z")

</div>

Hi Experts,  
i am able to connect the ES7.17 through tcp port , but in ES 8.8 library there is no class to connect tcp port.  
Some code snippet is working in ES 7.17:

```auto
Client getClient() {
		Settings settings = Settings.builder()
				.put("client.transport.sniff", true)
				.put("xpack.security.transport.ssl.keystore.path", env.getProperty("es.path.cert"))// link to pkcs12 file
				.put("xpack.security.transport.ssl.truststore.path", env.getProperty("es.path.cert"))// link to pkcs12 file
				.put("xpack.security.transport.ssl.enabled", "true")
				.put("xpack.security.transport.ssl.verification_mode", "certificate")
				.put("cluster.name", env.getProperty("es.cluster.name"))
				.put("xpack.security.user", env.getProperty("metrics.elasticsearch.client.username", "admin") + ":" + env.getProperty("metrics.elasticsearch.client.password", "password"))
				.build();

		@SuppressWarnings("deprecation")
		TransportClient client = new PreBuiltXPackTransportClient(settings);
		String hostsNames = env.getProperty("es.hosts.name"); //localhost:9300,localhost:10300
		String[] hosts = hostsNames.split(",");
		for (int i = 0; i < hosts.length; i++) {
			String host = hosts[i];
			log.info("ES host:port -> " + host); //localhost:9300
		    String[] esHost = host.split(":");
		    try {
				client.addTransportAddress(new TransportAddress(InetAddress.getByName(esHost[0]), Integer.valueOf(esHost[1])));

		    } catch (Exception e) {
				log.debug("unable to connect to elasticSearch" + e.getMessage());
			}
		}
		return client;
	}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2023, 7:40pm UTC](https://discuss.elastic.co/t/how-to-connect-es8-8-through-tcp-port-certificate-in-java/336793/2 "2023-06-23T19:40:35Z")

</div>

The transport client has been deprecated and [is no longer supported in Elasticsearch 8.x](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html). You should instead switch to [the new Java client](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html).

---

<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:** [July 21, 2023, 7:41pm UTC](https://discuss.elastic.co/t/how-to-connect-es8-8-through-tcp-port-certificate-in-java/336793/3 "2023-07-21T19:41:35Z")

</div>

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