Graph 如何在Gremlin中找到两个顶点之间的边ID

Graph 如何在Gremlin中找到两个顶点之间的边ID,graph,gremlin,gremlin-server,Graph,Gremlin,Gremlin Server,假设我们有一个具有多个顶点的图g,我们需要在顶点v1和具有IDid1和id2的顶点v2之间找到边和边ID 此操作的遍历过程仅为: g.V(id1).bothE().where(otherV().hasId(id2)) 我使用了bothE(),因为您没有说边是从v1到v2,还是从v1到v2。如果您已经知道方向,则应使用outE()或inE()。除此之外,当您知道边标签时,应将其提供给此步骤,以减少要遍历的边的数量 对于TinkerPop的现代图形,如下所示: gremlin> graph

假设我们有一个具有多个顶点的图g,我们需要在顶点v1和具有IDid1id2的顶点v2之间找到边和边ID

此操作的遍历过程仅为:

g.V(id1).bothE().where(otherV().hasId(id2))
我使用了
bothE()
,因为您没有说边是从v1到v2,还是从v1到v2。如果您已经知道方向,则应使用
outE()
inE()
。除此之外,当您知道边标签时,应将其提供给此步骤,以减少要遍历的边的数量

对于TinkerPop的现代图形,如下所示:

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().valueMap(true)
==>[name:[marko],label:person,id:1,age:[29]]
==>[name:[vadas],label:person,id:2,age:[27]]
==>[name:[lop],label:software,id:3,lang:[java]]
==>[name:[josh],label:person,id:4,age:[32]]
==>[name:[ripple],label:software,id:5,lang:[java]]
==>[name:[peter],label:person,id:6,age:[35]]
gremlin> g.V(1).bothE().where(otherV().hasId(2)).id()
==>7
并通过明确的方向和边缘标签进行优化:

gremlin> g.V(1).outE('knows').where(inV().hasId(2)).id()
==>7

如果您正在将gremlin python与orientDB一起使用,下面的代码片段将对您有所帮助

g.V(from_v_id).outE(label).where(__.inV().where(__.hasId("#" + to_v_id))).next()

谢谢你添加这个。关于gremlin python的文档非常糟糕。如果其他人能够在您遇到gremlin python文档时添加更多内容,这将非常有用。对于其他人来说,这可能也很有用:以下是一些gremlin python抽象,供其他感兴趣的人参考: