Java弹性搜索客户端始终为null [英] Java elasticsearch client always null

查看:123
本文介绍了Java弹性搜索客户端始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我已经从弹性搜索1.7到2.0,我注意到你设置客户端的方式已经改变了。我浏览了文档,由于某种原因,客户端始终为空。我想知道我是否正确设置。



这是我的代码:

 code> Client client = null; 

try {
client = TransportClient.builder()。build()。addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(localhost),9300));
} catch(Exception e){
Logger.log(e);
} finally {
client.close();
try {
conn.close();
} catch(SQLException e){
Logger.log(e);
}
}


解决方案

在评论中注意到,但更详细一点:Elasticsearch 2.0使用Guava 18.0(请参阅 https://github.com/弹性/ elasticsearch /拉/ 7593 )。所以要修复错误,如 java.lang.NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava / util / concurrent / Executor; ,确保使用Guava 18.0作为依赖,而不是其他版本。


I've recently made the switch from elasticsearch 1.7 to 2.0 and I noticed the way you setup the client has changed. I went through the documentation and for some reason the client is always null. I was wondering if I have set it up correctly.

Here is my code:

    Client client = null;

    try {
        client = TransportClient.builder().build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    } catch (Exception e) {
        Logger.log(e);
    } finally {
        client.close();
        try {
            conn.close();
        } catch (SQLException e) {
            Logger.log(e);
        }
    }

解决方案

As noted in the comments, but a little bit more in detail: Elasticsearch 2.0 uses Guava 18.0 (see https://github.com/elastic/elasticsearch/pull/7593). So to fix errors like java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concu‌rrent/Executor;, make sure to use Guava 18.0 as dependency and not other versions.

这篇关于Java弹性搜索客户端始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆