我正在尝试使用 janusgraph 创建一个架构,并使用 cassandra 作为后端存储,并使用 Elasticsearch 作为索引器。使用以下代码连接到 JanusGraph:
Graph graph = GraphFactory.open(CONFIG_FILE);
配置文件的内容是:
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=cassandrathrift
storage.hostname=127.0.0.1
storage.cassandra.keyspace=JanusGraph
cache.db-cache = true
cache.db-cache-clean-wait = 20
cache.db-cache-time = 180000
cache.db-cache-size = 0.25
index.search.backend=elasticsearch
index.search.hostname=127.0.0.1
index.search.port=9300
我创建索引的方式如下:
VertexLabel user = mgt.makeVertexLabel(USER).make();
PropertyKey userName =
mgt.makePropertyKey(USER_NAME).dataType(String.class).make();
//building mixed index (i.e. we use external indexer)
mgt.buildIndex(indexName(USER, USER_NAME), Vertex.class).
addKey(userName, Mapping.STRING.asParameter()).
indexOnly(user).
buildMixedIndex(BACKING_INDEX);
如您所见,我首先创建顶点,然后索引一些属性。
当我在不使用索引器的情况下运行代码时,我没有遇到问题,但是当我使用索引器时,我收到以下异常:
Exception in thread "main" java.lang.IllegalArgumentException: Could not find implementation class: org.janusgraph.diskstorage.es.ElasticSearchIndex
at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:60)
at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:476)
at org.janusgraph.diskstorage.Backend.getIndexes(Backend.java:463)
at org.janusgraph.diskstorage.Backend.<init>(Backend.java:148)
at org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:1840)
at org.janusgraph.graphdb.database.StandardJanusGraph.<init>(StandardJanusGraph.java:138)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:160)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:131)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:78)
at mounaf.janusgraph.Schema.<init>(Schema.java:61)
at mounaf.janusgraph.BuiltinQueries.main(BuiltinQueries.java:16)
Caused by: java.lang.ClassNotFoundException: org.janusgraph.diskstorage.es.ElasticSearchIndex
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:56)
... 10 more
你能帮我解决这个问题吗?
最佳答案
您收到ClassNotFoundException java.lang.ClassNotFoundException: org.janusgraph.diskstorage.es.ElasticSearchIndex
我认为您尚未在 pom.xml
文件中添加 janusgraph elasticsearch 依赖项。
在您的 pom.xml
文件中添加以下依赖项来解决此问题
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-es</artifactId>
<version>${janusgraph.version}</version>
<scope>runtime</scope>
</dependency>
关于java - 配置 JanusGraph 以通过 Java 使用 ElasticSearch 和 Cassandra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54134723/