我已经在Eclipse IDE中创建了一个Java项目,并且在一个类中有此代码。我已包含所有jar文件依赖项。
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY,Arrays.asList(
Netty3Plugin.class,
Netty4Plugin.class,
ReindexPlugin.class,
PercolatorPlugin.class,
MustachePlugin.class))
.addTransportAddress(new InetSocketTransportAddress(InetAddress
.getByName("https://search-my-test-domain-XXXXXXXXXXXXXXXXXXXXXX.us-east-1.es.amazonaws.com"), 9300));
但是当我运行代码时,会出现此错误,
Exception in thread "main" java.lang.NoSuchMethodError: org.elasticsearch.transport.client.PreBuiltTransportClient.addPlugins(Ljava/util/Collection;Ljava/util/Collection;)Ljava/util/Collection;
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:125)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:111)
at ESConnManager.retrieveDataFromES(ESConnManager.java:572)
at ESConnManager.main(ESConnManager.java:166)
我正在使用elasticsearch v5.3.2和Java api v5.3。有什么办法吗?
最佳答案
您不需要指定这五个插件,因为PreBuiltTransportClient
构造函数已默认加载了这五个插件,就像in the source code of PreBuiltTransportClient
所示
所以改用这个:
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress
.getByName("https://search-my-test-domain-XXXXXXXXXXXXXXXXXXXXXX.us-east-1.es.amazonaws.com"), 9300));
但是,由于您尝试访问一个AWS托管ES群集,因此请知道不支持传输客户端,因此只能通过HTTP而不是TCP访问AWS ES实例。您将收到的下一个错误是该节点不可用。