I'm able to connect to elastic search 6.1.0
and index, update, delete and query the documents via cURL and plugin head but I'm unable to connect to the same via the java client, ie,
/**
* Elasticsearch
*/
// https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch
compile group: 'org.elasticsearch', name: 'elasticsearch', version: '6.1.0'
// https://mvnrepository.com/artifact/org.elasticsearch.client/transport
compile group: 'org.elasticsearch.client', name: 'transport', version: '6.1.0'
dependencies. Below is elasticsearch.yml
#cluster.name: my-application
cluster.name: saasworthy-qa
node.name: qa-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
#network.host: 192.168.0.1
network.host: 10.10.10.2
#http.port: 9200
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#discovery.zen.ping.unicast.hosts: ["10.10.10.2"]
#discovery.zen.minimum_master_nodes: 1
The error received via java client is:
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{SLvQfw9FREWVhpwTBtjNWg}{X.X.X.X}{X.X.X.X:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:360)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:405)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:394)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46)
at com.sw.config.elastic.connection.factory.SaaSWorthyElasticsearchClientFactory.main
Also, netstat
info,
netstat -antp | grep 9300
tcp6 0 0 10.10.10.2:9300 :::* LISTEN 19768/java
Kindly help me out in resolving the issue. Thanks.
For Java Elasticsearch provides 2 sets of client API:
elasticsearch.yml for Java Transport Client (single node):
transport.host: localhost
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0
Java Transport client example:
// on startup
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
System.out.println(client.listedNodes());
// on shutdown
client.close();
To use Java Transport client we need the Bootstrap Checks need to be done which is quite difficult for a beginner.Its easier to use the Java REST client.
Note : Elasticsearch plans on deprecating the TransportClient in Elasticsearch 7.0 and removing it completely in 8.0. More information could be found here (just scroll down to search for the warning symbol).
I'm able to connect via the transport client after marking client.transport.sniff
as false
. As the server for dev environment, the cluster only contains one node.
For more info .
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.