Java弹性搜索客户端始终为null [英] Java elasticsearch client always null
问题描述
这是我的代码:
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/concurrent/Executor;
, make sure to use Guava 18.0 as dependency and not other versions.
这篇关于Java弹性搜索客户端始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!