0

我正在通过 Amazon Neptune 上的 Jupiter Notebook 使用 gremlin 遍历。
我试图通过标签过滤特定顶点的边缘,但它似乎不起作用。

一些样本数据:

%%gremlin
g.addV().property(id, 'u0').as('u0').
  addV().property(id, 'u1').as('u1').
  addV().property(id, 'u2').as('u2').
  addV().property(id, 'u3').as('u3').
  addE('freind').
    from('u0').
    to('u1').
  addE('buddy').
    from('u0').
    to('u2').
  addE('foe').
    from('u0').
    to('u3').
  iterate()

和我的查询:(
它比这个例子需要的更复杂,但我的实际查询重复了几次,因此我不能简单地使用 has('friend').has('buddy') 因为下一步还有其他标签.)

%%gremlin
g.withSack(1.0f).V('u0')
    .repeat(
        bothE().hasNot('foe')
        .bothV())
    .times(1)
    .path().by().by(label)

输出:

path[v[u0], freind, v[u1]]
path[v[u0], buddy, v[u2]]
path[v[u0], foe, v[u3]]

我有一个用户,我从 (u0) 开始,希望所有用户都是他的朋友、好友等,而不是他的敌人。

不幸的是,它没有按应有的方式过滤...任何想法我做错了什么?

4

1 回答 1

1

hasNot()步骤将仅过滤掉具有指定名称的属性的元素,在本例中为名为 的属性foe。相反,您应该使用not()withhasLabel()来查找没有特定标签的项目,如下所示:

g.withSack(1.0f).V('u0')
    .repeat(
        bothE().not(hasLabel('foe'))
        .bothV())
    .times(1)
    .path().by().by(label)  
于 2022-02-04T17:42:50.423 回答