我能够连接到弹性搜索DateTime Data
2017-11-21 18:54:31 1
2017-11-22 02:26:48 1
2017-11-22 10:19:44 1
2017-11-22 15:11:28 1
2017-11-22 23:21:58 1
2017-11-28 14:28:28 1
2017-11-28 14:36:40 0
2017-11-28 14:59:48 1
并通过cURL和插件头索引,更新,删除和查询文档但我无法通过java客户端连接到文档,即
6.1.0
依赖性。
以下是 /**
* 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'
elasticsearch.yml
通过java客户端收到的错误是:
#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
此外,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
信息,
netstat
请帮助我解决问题。感谢。
答案 0 :(得分:1)
对于Java,Elasticsearch提供了2组客户端API:
用于Java传输客户端的elasticsearch.yml(单节点):
transport.host: localhost
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0
Java Transport客户端示例:
// on startup
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
System.out.println(client.listedNodes());
// on shutdown
client.close();
要使用Java Transport客户端,我们需要完成 Bootstrap Checks ,这对初学者来说非常困难。它更容易使用Java REST客户端。
注意:Elasticsearch计划在Elasticsearch 7.0中弃用 TransportClient ,并在8.0中完全删除。更多信息 可以找到 here (只需向下滚动即可搜索 警告符号)。
答案 1 :(得分:0)
将client.transport.sniff
标记为false
后,我可以通过传输客户端进行连接。作为开发环境的服务器,集群只包含一个节点。
了解更多info。