[英]Why this error coming failed to load elasticsearch nodes in spring boot?
我正在嘗試在我的網絡應用程序中使用 elasticsearch。 我正在使用spring 啟動 2.0.6 。 我沒有添加任何配置文件彈性搜索是由 spring 啟動自動配置的。 我在 application.properties 中添加了 spring 數據彈性搜索屬性,如下所示
彈簧數據彈性搜索-3.0.11
elasticsearch-5.6.12
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=localhost:9300
spring.data.elasticsearch.properties.node.master: true
spring.data.elasticsearch.properties.node.data: false
spring.data.elasticsearch.properties.node.name: my-node
spring.data.elasticsearch.properties.node.attr.type: hot
spring.data.elasticsearch.properties.http.enabled: true
spring.data.elasticsearch.repositories.enabled=true
當我運行我的應用程序控制台顯示
o.elasticsearch.plugins.PluginsService : no modules loaded
o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 127.0.0.1:9300
我添加了一個用於演示目的的簡單示例,但出現此錯誤
.der.s.AbstractElasticsearchRepository: failed to load elasticsearch nodes: org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{zYXxPcpaQ_6I9GI2yID8cQ}{localhost}{127.0.0.1:9300}]
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loaders':
Invocation of init method failed; nested exception is NoNodeAvailableException
[None of the configured nodes are available: [{#transport#-1}{zYXxPcpaQ_6I9GI2yID8cQ}{localhost}{127.0.0.1:9300}]]
這是我用過的例子
用戶.java
@Document(indexName = "users", type = "users", shards = 1, replicas = 0, refreshInterval = "-1")
public class Users {
private String name;
private Long id;
private String teamName;
private Long salary;
裝載機.java
@Component
public class Loaders {
@Autowired
ElasticsearchOperations operations;
@Autowired
UsersRepository usersRepository;
@PostConstruct
@Transactional
public void loadAll(){
operations.putMapping(Users.class);
System.out.println("Loading Data");
usersRepository.saveAll(getData());
System.out.printf("Loading Completed");
}
private List<Users> getData() {
List<Users> userses = new ArrayList<>();
userses.add(new Users("Ajay",123L, "Accounting", 12000L));
userses.add(new Users("Jaga",1234L, "Finance", 22000L));
userses.add(new Users("Thiru",1235L, "Accounting", 12000L));
return userses;
}
}
UsersRepository.java
public interface UsersRepository extends ElasticsearchRepository<Users, Long> {
List<Users> findByName(String text);
List<Users> findBySalary(Long salary);
}
為什么我收到錯誤? 我應該使用任何其他屬性嗎?
從這里https://www.elastic.co/downloads/elasticsearch#ga-release下載elasticsearch 5.6.12后我的問題解決了
並添加配置文件
@Bean
public Client client() throws UnknownHostException {
Settings settings = Settings.builder()
.put("client.transport.sniff", true)
.put("cluster.name", "elasticsearch").build();
@SuppressWarnings("resource")
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
return client;
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(client());
}
僅根據稀疏信息在此處進行粗略猜測,而未提供任何配置詳細信息(請添加這些信息以進行進一步調試):如果您使用的是 docker,您的應用程序中的 127.0.0.1 可能無法使用您的 elasticsearch 集群?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.