通过 Java 配置 JanusGraph 以使用 Lucene
Configuring JanusGraph to use Lucene via Java
我正在尝试使用以下代码连接到 JanusGraph:
Graph graph = GraphFactory.open(new PropertiesConfiguration("janusgraph.propertes");
我的janusgraph.properties
文件如下:
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=hbase
storage.hostname=127.0.0.1
cache.db-cache = true
cache.db-cache-clean-wait = 20
cache.db-cache-time = 180000
cache.db-cache-size = 0.5
index.janusgraph-index.backend=lucene
但是,当我尝试连接时出现以下错误:
Exception in thread "Thread-4" java.lang.RuntimeException: GraphFactory could not instantiate this Graph implementation [class org.janusgraph.core.JanusGraphFactory]
at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:82)
at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:70)
at uk.gov.nca.cdp.graphutils.server.controllers.MergeGraph.lambda$merge[=13=](MergeGraph.java:26)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:78)
... 3 more
Caused by: java.lang.IllegalArgumentException: Could not find implementation class: org.janusgraph.diskstorage.es.ElasticSearchIndex
at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:61)
at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:477)
at org.janusgraph.diskstorage.Backend.getIndexes(Backend.java:464)
at org.janusgraph.diskstorage.Backend.<init>(Backend.java:149)
at org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:1897)
at org.janusgraph.graphdb.database.StandardJanusGraph.<init>(StandardJanusGraph.java:136)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:164)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:133)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:113)
... 8 more
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 org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
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)
... 16 more
这听起来像是在尝试使用 Elasticsearch 而不是 Lucene。如何正确配置它以使用 Lucene?
您 运行 遇到的问题是您的配置没有定义 storage.hbase.table
,因此使用默认的 table 名称 janusgraph
(请参阅 JanusGraph configuration reference).之前必须使用 Elasticsearch 为索引提供程序创建名为 janusgraph
的 HBase table。 JanusGraph 将其初始配置存储在 HBase table 中,因此当您连接到 janusgraph
table 时,它会从 janusgraph
table 读取旧属性。您应该:
- 删除现有的
janusgraph
HBase table。来自 HBase shell:disable 'janusgraph'; drop 'janusgraph';
- 通过设置
storage.hbase.table=mygraph
使用不同的 HBase table
如 JanusGraph Lucene documentation 中所述,Lucene 索引后端在其配置中需要两个参数:
index.[X].backend=lucene
index.[X].directory=/data/searchindex
其中 [X]
是索引的名称。您可以将其设置为与示例中常见的目录名称 searchindex
或 search
或问题中的 janusgraph-index
相匹配。确保包括这两个配置属性。
我正在尝试使用以下代码连接到 JanusGraph:
Graph graph = GraphFactory.open(new PropertiesConfiguration("janusgraph.propertes");
我的janusgraph.properties
文件如下:
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=hbase
storage.hostname=127.0.0.1
cache.db-cache = true
cache.db-cache-clean-wait = 20
cache.db-cache-time = 180000
cache.db-cache-size = 0.5
index.janusgraph-index.backend=lucene
但是,当我尝试连接时出现以下错误:
Exception in thread "Thread-4" java.lang.RuntimeException: GraphFactory could not instantiate this Graph implementation [class org.janusgraph.core.JanusGraphFactory]
at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:82)
at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:70)
at uk.gov.nca.cdp.graphutils.server.controllers.MergeGraph.lambda$merge[=13=](MergeGraph.java:26)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:78)
... 3 more
Caused by: java.lang.IllegalArgumentException: Could not find implementation class: org.janusgraph.diskstorage.es.ElasticSearchIndex
at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:61)
at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:477)
at org.janusgraph.diskstorage.Backend.getIndexes(Backend.java:464)
at org.janusgraph.diskstorage.Backend.<init>(Backend.java:149)
at org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:1897)
at org.janusgraph.graphdb.database.StandardJanusGraph.<init>(StandardJanusGraph.java:136)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:164)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:133)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:113)
... 8 more
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 org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
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)
... 16 more
这听起来像是在尝试使用 Elasticsearch 而不是 Lucene。如何正确配置它以使用 Lucene?
您 运行 遇到的问题是您的配置没有定义 storage.hbase.table
,因此使用默认的 table 名称 janusgraph
(请参阅 JanusGraph configuration reference).之前必须使用 Elasticsearch 为索引提供程序创建名为 janusgraph
的 HBase table。 JanusGraph 将其初始配置存储在 HBase table 中,因此当您连接到 janusgraph
table 时,它会从 janusgraph
table 读取旧属性。您应该:
- 删除现有的
janusgraph
HBase table。来自 HBase shell:disable 'janusgraph'; drop 'janusgraph';
- 通过设置
storage.hbase.table=mygraph
使用不同的 HBase table
如 JanusGraph Lucene documentation 中所述,Lucene 索引后端在其配置中需要两个参数:
index.[X].backend=lucene
index.[X].directory=/data/searchindex
其中 [X]
是索引的名称。您可以将其设置为与示例中常见的目录名称 searchindex
或 search
或问题中的 janusgraph-index
相匹配。确保包括这两个配置属性。