I'm using the Java API. I tried the following:
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
But it gave me the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.elasticsearch.client.transport.TransportClient$Builder.<init>(TransportClient.java:84)
at org.elasticsearch.client.transport.TransportClient.builder(TransportClient.java:76)
at tools.Tools.Searcher(Tools.java:195)
at tools.Tools.main(Tools.java:60)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more
Java Result: 1
I am using Elasticsearch 2.0.0 and it is running on port 9200
What is causing that error and how can I fix it?
I have this problem too, but when i add the guava-18.0.jar into build path ,it works. Hope it works for you.
You can use Unirest API for Java. It is very easy to use.
Check it's documentation. I myself am a beginner and I found this very easy to implement.
Just add the following maven dependency in your pom file.
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.7</version>
</dependency>
And your java implementation would be like this:
HttpResponse<String> response = Unirest.get("http:localhost:9200").asString();
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.