Elasticsearch API Client API

I want to run the following java code:

import java.util.Map;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;

public class MongoDB {

public static void main(String[] args) {
    Node node = nodeBuilder().clusterName("elasticsearch").client(true).node();
    Client client = node.client();


    node.close();
}  
}

I started mongod with the following command:

mongod --port 27017 --replSet rs0

Elastic default search conf

And every time I run my program, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
  at org.elasticsearch.Version.<clinit>(Version.java:42)
  at org.elasticsearch.Version.<clinit>(Version.java:42)
  at org.elasticsearch.node.internal.InternalNode.<init>(InternalNode.java:129)
  at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:159)
  at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:166)
  at org.elasticsearch.river.mongodb.MongoDB.main(MongoDB.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
  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)
... 5 more
Java Result: 1
+4
source share
3 answers

Elasticsearchis a search based server Lucene. you must include the lucene jar file lucene-core-x.x.x.jarand other dependent jar files for this code to work ...

+8
source

Use java client to find elasticity. You have 2 dependencies.
Elasticsearch jar and amber anchor pit ...

, names.txt .

, ...

+1

NodeBuilder is no longer used with the latest ES (5.6.3).
Avoid using it and start using TransportClient for future support.

For more information: https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_java_api_changes.html

0
source

Source: https://habr.com/ru/post/1532697/


All Articles