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

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:

Client getClient() {
		Settings settings = Settings.builder()
				.put("client.transport.sniff", true)
				.put("", env.getProperty("es.path.cert"))// link to pkcs12 file
				.put("", env.getProperty("es.path.cert"))// link to pkcs12 file
				.put("", "true")
				.put("", "certificate")
				.put("", env.getProperty(""))
				.put("", env.getProperty("metrics.elasticsearch.client.username", "admin") + ":" + env.getProperty("metrics.elasticsearch.client.password", "password"))

		TransportClient  client = new PreBuiltXPackTransportClient(settings);
		String hostsNames = env.getProperty(""); //localhost:9300,localhost:10300
		String[] hosts = hostsNames.split(",");
		for (int i = 0; i < hosts.length; i++) {
			String host = hosts[i];"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;

The transport client has been deprecated and is no longer supported in Elasticsearch 8.x. You should instead switch to the new Java client.

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