ElasticSearch TransportClient 5.6版

时间:2017-11-02 15:04:57

标签: java elasticsearch

我是Elastisearch Java API的新手

我安装了5.6版我的服务器elasticsearch正在

中运行

http://localhost:9200/

 {
      "name" : "KJj0iv3",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "0je2mMloQ52X_GT1itxGuA",
      "version" : {
        "number" : "5.6.3",
        "build_hash" : "1a2f265",
        "build_date" : "2017-10-06T20:33:39.012Z",
        "build_snapshot" : false,
        "lucene_version" : "6.6.1"
      },
      "tagline" : "You Know, for Search"
    }

这是我的类Test Java

public static void main(String[] args) throws UnknownHostException {
    try {
        TransportClient client;

        client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
        // on shutdown
        client.close();
    } catch (ElasticsearchException e) {
        System.out.println(e.getMessage());
    }
}

这是我的错误

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.debug(Ljava/lang/String;Ljava/lang/Object;)V
    at org.elasticsearch.threadpool.ThreadPool.<init>(ThreadPool.java:203)
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:129)
    at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:265)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:130)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:116)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:106)
    at queryDsl.Test.main(Test.java:24)

1 个答案:

答案 0 :(得分:1)

使用端口9300代替9200,因为TransportClient需要端口9300,因为它使用传输模块进行通信。