简体   繁体   English

尝试创建TransportClient时,Elasticsearch 5.1错误“ java.lang.NoSuchFieldError:LUCENE_5_4_1”

[英]Elasticsearch 5.1 error “java.lang.NoSuchFieldError: LUCENE_5_4_1” when trying to create a TransportClient

I am trying to write a client for Elasticsearch 5.1, and am trying to use the TransportClient object, as documented here ( https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.1/transport-client.html ). 我正在尝试为Elasticsearch 5.1编写客户端,并试图使用TransportClient对象,如此处所述( https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.1/transport- client.html )。

To test this client, I have a simple get function that uses the Get API as documented on the ES site ( https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-get.html ). 为了测试此客户端,我有一个简单的get函数,该函数使用ES网站上记录的Get API( https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs -get.html )。

However, my code does not even execute to my get function, but rather throws the error upon creation of a PreBuiltTransportClient object I create in the constructor of my client class. 但是,我的代码甚至没有执行我的get函数,而是在创建我在客户端类的构造函数中创建的PreBuiltTransportClient对象时引发错误。 Below, is the snippet of code. 下面是代码片段。 The error gets thrown from that first line. 错误从第一行引发。

PreBuiltTransportClient preBuiltTransportClient = new PreBuiltTransportClient(Settings.EMPTY);
try{
    this.esClient = (TransportClient) preBuiltTransportClient.addTransportAddress(
            new InetSocketTransportAddress(InetAddress.getByName(esHost), esPort));
} catch (UnknownHostException ex) {
    LOGGER.error("Host cannot be reached: ", ex);
    preBuiltTransportClient.close();
    this.esClient.close();
}

Here is the way I am testing the client with the get API. 这是我使用get API测试客户端的方法。 The search values are from the elasticsearch github example ( https://github.com/elastic/elasticsearch ). 搜索值来自elasticsearch github示例( https://github.com/elastic/elasticsearch )。

//for testing purposes
public void testGet(String index, String type, String id) {
    GetResponse response = esClient.prepareGet(index, type, id).get();
    System.out.println("testGet response: " + response);
}

public static void main(String[] args) {
    ESClient = new ESClient("localhost", 9200);
    String index = "twitter"; 
    String type = "tweet";
    String id = "kimchy";
    client.testGet(index, type, id);
}

Lastly, below is the full stack trace of the error: 最后,下面是错误的完整堆栈跟踪:

Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_5_4_1
at org.elasticsearch.Version.<clinit>(Version.java:57)
at org.elasticsearch.common.io.stream.StreamOutput.<init>(StreamOutput.java:74)
at org.elasticsearch.common.io.stream.BytesStreamOutput.<init>(BytesStreamOutput.java:60)
at org.elasticsearch.common.io.stream.BytesStreamOutput.<init>(BytesStreamOutput.java:57)
at org.elasticsearch.common.io.stream.BytesStreamOutput.<init>(BytesStreamOutput.java:47)
at org.elasticsearch.common.xcontent.XContentBuilder.builder(XContentBuilder.java:69)
at org.elasticsearch.common.settings.Setting.arrayToParsableString(Setting.java:726)
at org.elasticsearch.common.settings.Setting.lambda$listSetting$26(Setting.java:672)
at org.elasticsearch.common.settings.Setting$2.getRaw(Setting.java:676)
at org.elasticsearch.common.settings.Setting.lambda$listSetting$24(Setting.java:660)
at org.elasticsearch.common.settings.Setting.listSetting(Setting.java:665)
at org.elasticsearch.common.settings.Setting.listSetting(Setting.java:660)
at org.elasticsearch.common.network.NetworkService.<clinit>(NetworkService.java:50)
at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:91)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:119)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:247)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:92)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:81)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:71)
at customclient.<init>(ESClient.java:43)
at customclient.main(ESClient.java:112)

I'm not sure what this error is caused by, or what I could be doing wrong, and would appreciate some help! 我不确定此错误是由什么引起的,或者我可能做错了什么,将不胜感激! Thanks! 谢谢!

Aren't you suppose to have the latest version of Lucene as per the ES blog blog which I've posted below? 根据我在下面发布的ES博客博客,您是否不应该拥有Lucene的最新版本?

Today we are pleased to announce the release of Elasticsearch 5.1.1, based on Lucene 6.3.0. 今天,我们很高兴宣布基于Lucene 6.3.0的Elasticsearch 5.1.1版本。

source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM