Neo4j 为什么gremlinidx返回null,尽管DB不是空的?
我正在使用以下方法打开图形:Neo4j 为什么gremlinidx返回null,尽管DB不是空的?,neo4j,graph-databases,gremlin,Neo4j,Graph Databases,Gremlin,我正在使用以下方法打开图形: g = new Neo4jGraph('...path...'); 然后使用以下命令添加顶点: myVertex = g.addVertex(['type':'X', 'Y':Z]); 我可以看到db有一个顶点(使用Gephi) 但当我跑步时: if (g.idx(T.v) != null ) 它总是返回false。 是否应该以某种方式打开索引? Gremlin是否需要特定的Neo4j版本 添加一些日志信息: ... ==>v[22092] ==>
g = new Neo4jGraph('...path...');
然后使用以下命令添加顶点:
myVertex = g.addVertex(['type':'X', 'Y':Z]);
我可以看到db有一个顶点(使用Gephi)
但当我跑步时:
if (g.idx(T.v) != null )
它总是返回false。
是否应该以某种方式打开索引?
Gremlin是否需要特定的Neo4j版本
添加一些日志信息:
...
==>v[22092]
==>v[22093]
==>v[22094]
==>v[22095]
gremlin> g.idx(T.v)
==>null
gremlin> g.idx("vertices")
==>null
gremlin> g.indices
gremlin>
在Gremlin1.3上尝试了这个-同样的结果。所以我想这是我遗漏的东西。我认为用Gremlin在Neo4j中创建索引可能会失败。证据包括针对和提出的问题。即使不是这样,Gremlin在Neo4j中也没有一流的索引访问权限——例如,上次我检查时,它无法创建全文索引。不确定它是否能在Neo中创建关系索引 我使用了一个Gremlin/Groovy代码段 我意识到这打破了Gremlin的良好抽象层,但之后你可以使用Gremlin方法,比如
g.idx('vertices')
编辑:
要在索引更改对Gremlin“可见”之前访问索引,请尝试以下操作:
import com.tinkerpop.blueprints.pgm.impls.neo4j.Neo4jIndex;
ind = new Neo4jIndex('vertices', Vertex.class, g)
与我在评论中链接的要点相比,它的优点是
ind
是一个小精灵索引,可以应用到一般小精灵治疗的一半。OTOH,注释中的要点可以完全访问原始索引。如何在Neo4j web控制台中使用Gremlin创建Neo4j索引:
gremlin> g.createManualIndex('test2', Vertex.class)
==> MANUAL[test2:Vertex]
gremlin> test2=g.idx('test2')
==> MANUAL[test2:Vertex]
gremlin> hendy=g.v(1673)
==> v[1673]
gremlin> hendy.name
==> Hendy Irawan
gremlin> test2.put('name', 'Hendy Irawan', hendy)
==>
gremlin> test2.get('name', 'Hendy Irawan')
==> v[1673]
注意:g.createAutomaticIndex()
不会像大多数人在这里期望的那样,它将创建一个Neo4j手动索引,该索引由蓝图自动更新,以索引具有名称
属性的所有节点(即顶点
类)
摘自:
参考资料:谢谢你的回答,这让我更进一步了。现在已创建索引,但它仅在脚本的第二次运行时有效。好像没有“提交”(尝试使用tx.success/finish)。你知道如何克服这个问题吗?恐怕这是Gremlin/Neo4j指数问题的一部分——至少在这些问题上是如此。看起来Gremlin将所有名称/索引绑定到hashmap,而不是每次调用g.idx()时都查找它们。。。嗯,一个解决办法是继续使用原始的Neo4j指数,就像下面的要点一样
gremlin> g.createManualIndex('test2', Vertex.class)
==> MANUAL[test2:Vertex]
gremlin> test2=g.idx('test2')
==> MANUAL[test2:Vertex]
gremlin> hendy=g.v(1673)
==> v[1673]
gremlin> hendy.name
==> Hendy Irawan
gremlin> test2.put('name', 'Hendy Irawan', hendy)
==>
gremlin> test2.get('name', 'Hendy Irawan')
==> v[1673]