graphgremlinamazon-neptunegraph-notebook

hasNot() having no effect


I'm using gremlin traversals via a Jupiter Notebook on Amazon Neptune.
I'm trying to filter edges from a specific vertex by their label, but it doesn't seem to work.

some sample data:

%%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()

and my query:
(It is more complex than needed for this example, but my actual query repeats several times, therefore I can't simply use has('friend').has('buddy') because the next step has other labels.)

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

output:

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

I have a user I start with (u0) and want all user who are his friends, buddies, and so on, but not his foes.

unfortunately its not filtering as its supposed to... any Idea what I'm doing wrong?


Solution

  • The hasNot() step will only filter out elements that have a property with the specified name, in this case a property named foe. Instead, you should look at using not() with hasLabel() to find items that do not have a specific label, as shown here:

    g.withSack(1.0f).V('u0')
        .repeat(
            bothE().not(hasLabel('foe'))
            .bothV())
        .times(1)
        .path().by().by(label)