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

本机项目访问阿里云部署的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服务, 想在本机访问 ,遇到了这个问题  

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_42475367/article/details/90767057
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-02-25 01:06:42
  • 阅读 ( 1345 )
  • 分类:职场

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢