【问题标题】:Configuring JanusGraph to use ElasticSearch and Cassandra via Java通过 Java 配置 JanusGraph 以使用 ElasticSearch 和 Cassandra
【发布时间】:2019-12-30 13:08:42
【问题描述】:

我正在尝试使用 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 elasticsearch graph cassandra janusgraph


    【解决方案1】:

    你得到 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>
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2017-11-28
        • 2023-02-22
        • 2017-10-03
        • 2021-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多