Spring 数据 ElasticSearch - 无法连接到节点
Spring Data ElasticSearch - cannot connect to node
我正在尝试在 Spring MVC 应用程序中配置 ElasticSearch 存储库。
我正在使用 Spring Data ElasticSearch 版本:2.0.7 和 ElasticSearch Server 2.4.4。
我确定 ElasticNode 可以正常工作,这里是示例输出
$ curl -X GET http://127.0.0.1:9200/
{
"name" : "Tattoo",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dX0lPfNnSA6vxGqhzVEuSg",
"version" : {
"number" : "2.4.4",
"build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",
"build_timestamp" : "2017-01-03T11:33:16Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
这是我的测试配置
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.somepackage.repo.elastic")
public class ElasticSearchConfig {
@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(nodeClient());
}
@Bean
public TransportClient nodeClient() throws UnknownHostException {
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = TransportClient.builder()
.settings(settings)
.build();
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
return client;
}
}
我收到应用程序无法连接到 Elastic 节点的错误,stacktrace
2017-02-17 23:34:53 INFO transport:383 - [Impulse] failed to get node info for {#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}, disconnecting...
ReceiveTimeoutTransportException[[][localhost/127.0.0.1:9200][cluster:monitor/nodes/liveness] request_id [1] timed out after [5002ms]]
at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:645)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我尝试将弹性搜索节点的版本从 1.7.1、2.4.4 和 5.2.1 更改。什么都不管用。
Spring MVC 4.3.6.RELEASE 与 Java 8
Transport client 通过端口 9300 与 elasticsearch 通信。所以尝试
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
简而言之:ElasticSearch节点和TransportClient应该有相同的版本。
Spring 数据 ElasticSearch 在 2.2.0 版本中提供了 TransportClient。我在 2.4.4 版中使用 ElasticSearch 节点。我将 ES 节点降级到 2.2.0,并在配置中将端口从 9200 更改为 9300。
我正在尝试在 Spring MVC 应用程序中配置 ElasticSearch 存储库。 我正在使用 Spring Data ElasticSearch 版本:2.0.7 和 ElasticSearch Server 2.4.4。
我确定 ElasticNode 可以正常工作,这里是示例输出
$ curl -X GET http://127.0.0.1:9200/
{
"name" : "Tattoo",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dX0lPfNnSA6vxGqhzVEuSg",
"version" : {
"number" : "2.4.4",
"build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",
"build_timestamp" : "2017-01-03T11:33:16Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
这是我的测试配置
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.somepackage.repo.elastic")
public class ElasticSearchConfig {
@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(nodeClient());
}
@Bean
public TransportClient nodeClient() throws UnknownHostException {
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = TransportClient.builder()
.settings(settings)
.build();
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
return client;
}
}
我收到应用程序无法连接到 Elastic 节点的错误,stacktrace
2017-02-17 23:34:53 INFO transport:383 - [Impulse] failed to get node info for {#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}, disconnecting...
ReceiveTimeoutTransportException[[][localhost/127.0.0.1:9200][cluster:monitor/nodes/liveness] request_id [1] timed out after [5002ms]]
at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:645)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我尝试将弹性搜索节点的版本从 1.7.1、2.4.4 和 5.2.1 更改。什么都不管用。 Spring MVC 4.3.6.RELEASE 与 Java 8
Transport client 通过端口 9300 与 elasticsearch 通信。所以尝试
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
简而言之:ElasticSearch节点和TransportClient应该有相同的版本。
Spring 数据 ElasticSearch 在 2.2.0 版本中提供了 TransportClient。我在 2.4.4 版中使用 ElasticSearch 节点。我将 ES 节点降级到 2.2.0,并在配置中将端口从 9200 更改为 9300。