我正在尝试在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;
}
}
我收到应用程序无法连接到 flex 节点的错误,堆栈跟踪
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)
我试图将 flex 搜索节点的版本从1.7.1、2.4.4和5.2.1更改。没事。
使用Java 8的Spring MVC 4.3.6.RELEASE
最佳答案
Transport client通过端口9300与elasticsearch对话。因此,请尝试
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
关于elasticsearch - Spring Data ElasticSearch-无法连接到节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42308671/