Elastic search 5.0 java transport client not working

For the below code.

The preBuildTransportClient class asks to two parameters.

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class EsTest {

public static void main(String[] args) {
	
	 Settings settings = Settings.builder()
             .put("cluster.name", "my-application")
             .put("client.transport.sniff", true)
             .build();

     TransportClient client = new PreBuiltTransportClient(settings);

     client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.32.124"), 9300));

}

}

We have added transport-5.0.1 jar. Could you please suggest which jar we could use to solve this issue in elasticsearch version 5 ?

Please format your code using </> icon. It will make your post more readable.

Can you tell what exactly the issue is?

Dependency error PreBuiltTransportClient. The constructor PreBuiltTransportClient(Settings) is undefined. How to fix this issue ?

May be you did not add all the needed dependencies because you are not using something like Maven?

Did you follow the guide here: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_maven_repository.html ?

We are not using maven but we have included all the dependencies. But still getting error ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

Try searching for the error message you got:

No log4j2 configuration file found. Using default configuration:

with your favorite search engine, there are a couple relevant threads over on Stackoverflow that might help you out here.

We are getting this exception in elasticsearch5 how to fix this issue ?
We have already tried but no luck ...
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{G3cU-l9lQhO9ZFJhEvkrEA}{127.0.0.1}{127.0.0.1:9300}]]

It seems that elatic search instance you started did not start with the default transport client i.e 9300 set in the elasticsearch.yml file having the value transport client set to 9300.

Check your transport client port which appears when you start the elastic search and copy that port to the transportclient variable in the elasticsearch.yml file.
This might solve your problem and then re-start your elastic search and check that the port you mentioned is the same as the transport client value when elasticsearch starts.

Thank you for the suggestions its working now :slight_smile:

:+1: great :slight_smile:

Does the search template option is removed in elasticsearch 5.0. Please refer the link of version 1.6 https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.6/java-search-template.html but there is no option for version 5. How to do template queries in elasticsearch 5 ?

I think the documentation page you are looking for now lives here:

https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.x/java-specialized-queries.html#java-query-dsl-template-query

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