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 ).
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 ).
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. 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. The search values are from the elasticsearch github example ( 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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.