I am New in Elastic Search Java Api[5.0]. I am Using elasticsearch-5.0.0. I am try to create a Java Application(Maven) with Spring Boot. After run Application, it shows
2016-11-04 23:32:19.339 INFO 8280 --- [][generic][T#2]] org.elasticsearch.client.transport : [X-Ray] failed to get node info for [#transport#-1][DESKTOP-8SIPHSN][inet[localhost/127.0.0.1:9300]], disconnecting...
org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][cluster:monitor/nodes/info] disconnected
My Config File Is
@Configuration
public class ElasticsearchConfiguration {
@Bean
public Client client() {
TransportClient client = new TransportClient();
TransportAddress address = new InetSocketTransportAddress("localhost",9300);
client.addTransportAddress(address);
return client;
}
}
And I am using default cluster "elasticsearch". I need help to solve my issue with proper detection of causes.
Try using the PreBuiltTransportClient
mentioned in the 5.0 documentation:
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
Also note that the TransportClient
for ES version 2.x isn't compatible with 5.x:
The client must have the same major version (eg 2.x, or 5.x) as the nodes in the cluster. Clients may connect to clusters which have a different minor version (eg 2.3.x) but it is possible that new functionality may not be supported. Ideally, the client should have the same version as the cluster.
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html
Update
As a connectivity test, try executing the following simple program:
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class App {
public static void main(String[] args) throws UnknownHostException {
// The following settings aren't strictly necessary, because the default cluster name is "elasticsearch".
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
System.out.println(client.connectedNodes());
}
}
It should print to stdout something like the following line:
[{luhcORJ}{luhcORJOSzSLPBeXocDsuQ}{mkTJpwIAQGuNYTHfRLqUIw}{127.0.0.1}{127.0.0.1:9300}]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.