gpt4 book ai didi

java - Spring Boot 应用程序中的 Spring Data Elasticsearch

转载 作者:行者123 更新时间:2023-12-04 20:49:37 25 4
gpt4 key购买 nike

我有一个 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 INFO 25613 --- [ restartedMain] org.elasticsearch.plugins : [Aardwolf] loaded [], sites [] 2016-04-28 00:04:01.356 INFO 25613 --- [ restartedMain] org.elasticsearch.client.transport : [Aardwolf] failed to get node info for [#transport#-1][fathi-HP-Pavilion-g6-Notebook-PC][inet[localhost/127.0.0.1:9200]], disconnecting...

org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][cluster:monitor/nodes/info] request_id [0] timed out after [5001ms] at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:529) ~[elasticsearch-1.5.2.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_77] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_77] at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_77]

2016-04-28 00:04:01.512 ERROR 25613 --- [ restartedMain] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []

最佳答案

我从 ES 论坛得到了这个答案,它对我有用:

首先,Spring Data Elasticsearch 正式适用于 ES 1.x 版本(对我来说它适用于 1.7.1)。二、配置中使用的端口必须是9300

我进行了这些更改并且效果非常完美。

关于java - Spring Boot 应用程序中的 Spring Data Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36902060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com