在elasticsearch中获取TransportClient实例时获取ConnectTransportException

时间:2014-08-14 07:57:05

标签: java elasticsearch

我正在使用TransportClient创建带有以下代码的elasticsearch客户端实例。

public static Client getInstance() {
    String ipAddress = MessageTranslator.getMessage("es.cluster.ip");
    int transportClientPort = Integer.parseInt(MessageTranslator
                .getMessage("es.transportclient.port"));

    logger.debug("got the client ip as :" + ipAddress + " and port :"
            + transportClientPort);
    if (instance == null) {
        logger.debug("the client instance is null, creating a new instance");
        ImmutableSettings.Builder settings = ImmutableSettings
                .settingsBuilder();
        settings.put("node.client", true);
        settings.put("node.data", false);
        settings.put("node.name", "node-client");
        settings.put("cluster.name", "elasticsearch");
        settings.build();
        instance = new TransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(
                        ipAddress, transportClientPort));
        logger.debug("returning the new created client instance...");
        return instance;
    }
    logger.debug("returning the existing transport client object connection.");
    return instance;
}

问题有时代码正在工作并索引数据,但有时我遇到了以下问题。

  

14-08-2014 12:49:07,846 DEBUG   [elasticsearch [node-client] [transport_client_worker] [T#8] {新I / O.   worker#8}] org.elasticsearch.common.logging.log4j.Log4jESLogger 104 -   [node-client]与[[Nuke - Frank。]断开连接   辛普森] [P_OU-PZbTXyimWCOvkC7ow] [aricloudvmserver3.aricent.com] [INET [/10.203.238.139:9300]]],   频道关闭事件14-08-2014 12:49:11,134 DEBUG   [elasticsearch [节客户机] [通用] [T#1]]   org.elasticsearch.common.logging.log4j.Log4jESLogger 109 -   [node-client]无法连接到节点   [[#transport#-1] [BGHWV2099] [inet [/10.203.238.139:9300]]],从   节点列表org.elasticsearch.transport.ConnectTransportException:   [] [inet [/10.203.238.139:9300]] connect_timeout [30s] at   org.elasticsearch.transport.netty.NettyTransport.connectToChannelsLight(NettyTransport.java:683)     在   org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:643)     在   org.elasticsearch.transport.netty.NettyTransport.connectToNodeLight(NettyTransport.java:610)

请帮我找到问题。

由于

1 个答案:

答案 0 :(得分:0)

您的代码对我来说是正确的。如果这是间歇性问题,可以归结为:

  • 连接丢失

同样如上一篇文章所述,删除节点相关设置并尝试设置下面提到的属性

settingsBuilder.put("cluster.name", searchClusterName);
settingsBuilder.put("client.transport.sniff", true);
settingsBuilder.put("http.enabled", "false");

尝试一下并分享您的发现