通过java配置janusgraph以使用elasticsearch和cassandra

o2gm4chl  于 2021-06-14  发布在  Cassandra
关注(0)|答案(2)|浏览(708)

我正在尝试使用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);

如您所见,我首先创建顶点,然后索引一些属性。
当我在不使用indexer的情况下运行代码时,我没有遇到任何问题,但是当我使用indexer时,出现以下异常:

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

你能帮我解决这个问题吗。

smdncfj3

smdncfj31#

你得到了classnotfoundexception java.lang.ClassNotFoundException: org.janusgraph.diskstorage.es.ElasticSearchIndex 我想您还没有在您的应用程序中添加janusgraph elasticsearch依赖项 pom.xml 文件。将下面的依赖项添加到 pom.xml 文件来修复此问题

<dependency>
        <groupId>org.janusgraph</groupId>
        <artifactId>janusgraph-es</artifactId>
        <version>${janusgraph.version}</version>
        <scope>runtime</scope>
    </dependency>
zte4gxcn

zte4gxcn2#

我记得在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()"

相关问题