【发布时间】:2016-08-22 11:21:54
【问题描述】:
我有一个 Spring Boot 应用程序,我想在其中使用 Elastic search 2.2.0 独立(不是嵌入式服务器),我想使用 Spring Data Elastic search,那么 Spring Data 支持的 Elastic search 版本是什么以及如何我可以将其配置为连接到在 localhost:9200 中运行的 elasticsearch 实例吗?
实际上,我尝试将此选项添加到我的 application.properties 文件中:
spring.data.elasticsearch.repositories.enabled=true
spring.data.elasticsearch.cluster-nodes=localhost:9200
后来,我创建了这个配置类:
@Configuration
public class ElasticConfig {
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchTemplate(client());
}
@Bean
public Client client() {
TransportClient client = new TransportClient();
TransportAddress address = new InetSocketTransportAddress(
"localhost",9200);
client.addTransportAddress(address);
return client;
}
}
我得到了这个堆栈跟踪:
2016-04-28 00:03:52.246 信息 25613 --- [restartedMain] org.elasticsearch.plugins : [Aardwolf] 加载 [], 站点 [] 2016-04-28 00:04:01.356 信息 25613 --- [restartedMain] org.elasticsearch.client.transport : [Aardwolf] 未能获得 节点信息 [#transport#-1][fathi-HP-Pavilion-g6-Notebook-PC][inet[localhost/127.0.0.1:9200]],正在断开连接...
org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][集群:监视器/节点/信息] request_id [0] 在 [5001ms] 后超时 org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:529) ~[elasticsearch-1.5.2.jar:na] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_77] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_77] 在 java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_77]
2016-04-28 00:04:01.512 错误 25613 --- [restartedMain] .d.e.r.s.AbstractElasticsearchRepository :加载失败 弹性搜索节点: org.elasticsearch.client.transport.NoNodeAvailableException:没有 配置的节点可用:[]
【问题讨论】:
-
只是一个客户。请检查您的 elasticsearch 服务器状态。
-
@Gemini Keith:elasticsearch 已启动并运行:localhost:9200 { "name" : "Hildegarde", "cluster_name" : "elasticsearch", "version" : { "number" : "2.2. 0”,“build_hash”:“8ff36d139e16f8720f2947ef62c8167a888992fe”,“build_timestamp”:“2016-01-27T13:32:39Z”,“build_snapshot”:false,“lucene_version”:“5.4.1”},“标语”:“You知道,用于搜索”}
-
查看这个答案:stackoverflow.com/a/36858819/4604579。 Spring Data 还没有为 ES 2.x 做好准备
-
@Val 哪个版本的 ES,我可以使用?
标签: java spring elasticsearch spring-boot spring-data-elasticsearch