我在使用spring配置弹性搜索时遇到问题。我正在使用弹性搜索6.2.3。我一直遇到连接弹簧与弹性搜索“服务器”的问题。
首先我打开elasticsearch.bat
这是我的配置:
@Component
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.abc.portal.City")
@ComponentScan(basePackages = {"com.abc.portal.City"})
public class ElasticConfig {
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("node.name","node-1").put("client.transport.sniff", true).build();
Client client;
public ElasticConfig(){
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("localhost",9300)));
}
}
关于设置,我从elasticsearch.YML获取属性名称:
Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
最后我在application.properties中创建了prop:
spring.data.elasticsearch.cluster-nodes=localhost:9300
spring.data.elasticsearch.repositories.enabled=true
我的错误是:
failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{nMDmllJPQPitdDD8IEPKMA}{localhost}{127.0.0.1:9300}]
我做错了什么?
答案 0 :(得分:0)
提供端口9200或在您的Settings.builder.put
中指定