我想在我的类中创建一个main方法,以测试与elasticsearch引擎的连接
所以我想在弹性搜索的对象TransportClient的构造函数getConnection里面
这是我的代码,我只想测试我与elasticsearch的连接是否正常
(当我删除了弹性搜索的部分代码时,但是当我添加它时,我有这个错误)
Exception dans l'unité d'exécution "main"java.lang.UnsupportedClassVersionError: JVMCFRE003 version supérieure incorrecte; classe=org/elasticsearch/common/transport/TransportAddress, décalage=6
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:274)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:521)
at java.net.URLClassLoader.access$300(URLClassLoader.java:66)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:985)
at java.security.AccessController.doPrivileged(AccessController.java:284)
at java.net.URLClassLoader.findClass(URLClassLoader.java:416)
at java.lang.ClassLoader.loadClass(ClassLoader.java:652)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:346)
at java.lang.ClassLoader.loadClass(ClassLoader.java:618)
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
public class EsConnectionManagerBiz {
private String host;
private int port;
private String clusterName;
public EsConnection(String host, int port, String clusterName) {
super();
this.host = host;
this.port = port;
this.clusterName = clusterName;
}
public EsConnection() {
this.clusterName="elasticsearch";
this.port=9300;
this.host="localhost";
System.out.println(this.clusterName);
// probleme code start
InetSocketTransportAddress node;
try {
node = new InetSocketTransportAddress(InetAddress.getByName(this.host), this.port);
// settings elasticsearch
Settings settings = Settings.builder().put("cluster.name", this.clusterName)
.put("client.transport.sniff", true).build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(node);
System.out.println("================== " +client+" ========");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// end
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public static void main(String[] args) {
new EsConnection();
}
}
提前感谢您的帮助