如何获取未连接到x

时间:2017-06-29 20:03:18

标签: gremlin

给定节点v1和v2,如何在Gremlin中获取节点'#,它们连接到v1但未连接到v2。

除了v1之外,

t1也可以连接到其他节点,只要它不是v2即可。我试图用匹配来解决这个问题:

g.V().match(
__.as_("a").hasId(v1_id).inE('follows').otherV().as_("t1"), 
__.as_("b").hasId(v2_id).inE('follows').otherV().as_("t2")
).where('t1', P.neq('t2')).select('t1')

但出于某种原因我收到错误

{GremlinServerError} 500:提供的匹配模式无法解析:[[MatchStartStep(t1),WherePredicateStep(neq(t2)),MatchEndStep],[MatchStartStep(b),HasStep([~id.eq(1429616)] ),JanusGraphVertexStep(IN,[follow],edge),EdgeOtherVertexStep,MatchEndStep(t2)],[MatchStartStep(a),HasStep([~id.eq(1388760)]),JanusGraphVertexStep(IN,[follow],edge) ,EdgeOtherVertexStep,MatchEndStep(t1)]]

这些步骤本身似乎是正确的,因为它们按预期返回t1 / t2:

g.V().match(__.as_("a").hasId(v1_id).inE('follows').otherV().as_("t1"))
.select('t1')

我想我不太明白如何使用2场比赛的结合 - 请告知。

enter image description here

1 个答案:

答案 0 :(得分:1)

您不需要match()复杂度。从v1开始,遍历t并验证这些t是否未与v2相关联。

g.V(v1_id).in("follows").not(out("follows").hasId(v2_id))