我正在尝试使用janusgraph创建一个模式,并使用cassandra作为后端存储,并使用弹性搜索作为索引器。使用以下代码连接到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
你能帮助我解决这个问题。
我记得在java中使用openManagement方法时遇到问题,但我使用了client.submit(String gremlin)来配置我的模式和索引,并且它有效。
client.submit("mgt = graph.openManagement()\n" +
"user = mgt.makeVertexLabel(USER).make()\n" +
"userName = mgt.makePropertyKey(USER_NAME).dataType(String.class).make()\n" +
"mgt.buildIndex(indexName(USER, USER_NAME), Vertex.class).addKey(userName, Mapping.STRING.asParameter()).indexOnly(user).buildMixedIndex(BACKING_INDEX)\n" +
"mgmt.commit()"