Spring Data ElasticSearch - 无法连接到节点
问题描述:
我尝试在Spring MVC应用程序中配置ElasticSearch存储库。 我使用Spring Data ElasticSearch版本:2.0.7和ElasticSearch Server 2.4.4。Spring Data ElasticSearch - 无法连接到节点
我敢肯定,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;
}
}
我得到的错误,应用程序无法连接到弹性节点,堆栈跟踪
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
答
简而言之:ElasticSearch节点和TransportClient应具有相同的版本。
Spring Data ElasticSearch在版本2.2.0中提供了TransportClient。我在2.4.4版本中使用了ElasticSearch节点。我将ES节点降级到2.2.0,并将配置中的端口从9200更改为9300。
答
的Transport client会谈elasticsearch通过端口9300。因此,尝试
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
+0
这是部分解决方案:) –
你是对的。很高兴我没有遇到与TransportClient版本有关的问题。仍然很好知道未来。但是我有很多问题,因为我不了解9200和9300默认端口。这里是讨论何时使用哪一个帮助我:http://elasticsearch-users.115913.n3.nabble.com/Transport-Client-VS-REST-Client-td4042497.html – RenatoIvancic