行动是治愈恐惧的良药,而犹豫、拖延将不断滋养恐惧。

ES5.4中Java Transport Client 报错问题

Elasticsearch | 作者 wangjueying | 发布于2017年05月05日 | 阅读数:9021

如题,本人从5.1.2跟随每次版本升级java Transport client都没出现这个问题,今天升级到5.4.0后,ES集群没问题,工程配置依赖jar也没问题。
正常的搜索请求都没问题,而且也能正常返回结果,就是日志每隔几秒就出现如下日志,看起来很烦人。
日志如下
[elasticsearch[_client_][generic][T#3]] TransportClientNodesService$SniffNodesSampler$1$1.handleException (TransportClientNodesService.java:531) - failed to get local cluster state for {#transport#-1}{cAagOGR2SoSZJv5HEBB8GA}{172.xx.xx.xx}{172.xx.xx.xx:9300}, disconnecting...
org.elasticsearch.transport.ReceiveTimeoutTransportException: [172.xx.xx.xx:9300][cluster:monitor/state] request_id [2] timed out after [120009ms]
    at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:925) [elasticsearch-5.4.0.jar:5.4.0]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569) [elasticsearch-5.4.0.jar:5.4.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_111]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_111]

以及单次与集群建立通信的完整日志信息:
org.elasticsearch.transport.ReceiveTimeoutTransportException: [172.xx.xx.xx:9308][cluster:monitor/state] request_id [4] timed out after [120011ms]
    at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:925) [elasticsearch-5.4.0.jar:5.4.0]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569) [elasticsearch-5.4.0.jar:5.4.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_111]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_111]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{cAagOGR2SoSZJv5HEBB8GA}{172.xx.xx.xx}{172.xx.xx.xx:9300}]]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:348)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:246)
    at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:366)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)

其中172.xx.xx.xx是机器ip地址

试了好多种配置方法还是会每隔几秒一次打那个日志,求大神指定。
已邀请:

wangjueying - Java攻城狮-ES爱好者

赞同来自:

我把Settings.builder()里自动嗅探节点"client.transport.sniff"改成false虽然没问题了,但是很不科学啊

medcl - 今晚打老虎。

赞同来自:

一共几个节点啊?
172.xx.xx.xx:9308是那台节点啊?

syj - 90

赞同来自:

package es;

import java.net.InetAddress;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class esClient {
    private static Logger loger = null;
    public static void main(String[] args) {
        try {
            loger = LogManager.getLogger(esClient.class.getName());
            loger.info("start..");
            //设置集群名称
            Settings settings1 = Settings.builder().put("cluster.name", "my-elasticsearch")
                                                .put("client.transport.sniff", true).build();
            //创建client
           
            TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.140"), 9300));
                
            //搜索数据
            GetResponse response = client.prepareGet("blog", "article", "1").execute().actionGet();
            //输出结果
            System.out.println(response.getSourceAsString());
            //关闭client
            client.close();

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}





start..
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce
    at org.elasticsearch.common.settings.Settings$Builder.<init>(Settings.java:676)
    at org.elasticsearch.common.settings.Settings$Builder.<clinit>(Settings.java:671)
    at org.elasticsearch.common.settings.Settings.<clinit>(Settings.java:84)
    at es.esClient.main(esClient.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.SetOnce
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

报错,怎么解决啊?

要回复问题请先登录注册