Gremlin:在具有相同属性的节点之间添加边 [英] Gremlin: adding edges between nodes having the same property
问题描述
我是Gremlin的新手。我正在尝试使用Gremlin在DSE图上构建图。我能够创建顶点:
I am very new to Gremlin. I am trying to build a graph on DSE graph using Gremlin. I am able to create the vertices:
a = graph.addVertex(label, 'label1', 'key', 1)
b = graph.addVertex(label, 'label1', 'key', 2)
c = graph.addVertex(label, 'label2', 'key', 1)
d = graph.addVertex(label, 'label2', 'key', 2)
现在我要自动添加边线属性键匹配的两个带有不同标签的节点之间(即a和c之间以及b和c之间的create和edge)。我正在努力做到这一点。
Now i am looking to automatically add edges between two nodes with differents label where the property 'key' matches (i.e create and edge between a and c, and between b and c). I am stuggling to do that.
我尝试执行以下操作
g.V().hasLabel("label1").sideEffect{g.V().("label2").has("key",it.key).addEdge("link",it)}
但是出现以下错误:
No signature of method: org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_Traverser.values() is applicable for argument types: (java.lang.String) values: [key]
有人可以协助我解决这个问题吗?
预先感谢您
Can somebody assists me on this issue ? Thank you by advance
推荐答案
嵌套 gV()
通常是个坏主意。您可以使用单个遍历来解决问题:
Nested g.V()
's are usually a bad idea. You can solve the problem using a single traversal:
g.V().hasLabel("label1").as("a").
V().hasLabel("label2").as("b").
where("a", eq("b")).by("key").
addE("link").from("a").to("b")
还请注意,您必须允许在DSE Graph中进行扫描才能使遍历工作正常。
Also note that you'll have to allow scans in DSE Graph to make this traversal work.
这篇关于Gremlin:在具有相同属性的节点之间添加边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!