本机项目访问阿里云部署的elasticsearch服务报错: None of the configured nodes are available: [{#transport#-1}

 去网上查了好多资料,最后在下面这个博客中受到启发

https://blog.csdn.net/demon_LL/article/details/56852960

 如果设置client.transport.sniff为true,则表示客户端去嗅探整个cluster的状态,把集群中其它机器的ip地址加到客户端中

我想我已经配置了节点ip,为什么还要去"嗅探",抱着试一试的态度把这个配置给注释掉, 然后就 ok了

package com.imooc.config;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 邵少
 * @date 2019年5月26日
 */
@Configuration
public class ElasticSearchConfig {
	
	@Bean
	public TransportClient esClient() throws UnknownHostException{
		Settings settings = Settings.builder()
				.put("cluster.name", "elasticsearch")
//				.put("client.transport.sniff", true) // 自动发现节点
				.build();
				
		InetSocketTransportAddress master = new InetSocketTransportAddress(
				InetAddress.getByName("46.105.210.100"),9300
				);
		
		TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(master);
		return client;
	}
}

把这行配置注释掉

其实一开始我是访问本机部署的elasticsearch, 由于占用资源太多, 导致电脑太卡 , 就买了台阿里云服务器, 在阿里云服务器部署了elasticsearch服务, 想在本机访问 ,遇到了这个问题  

你可能感兴趣的:(Elasticsearch)