Omar Darwish
Omar Darwish

Reputation: 1655

Apache TinkerPop Gremlin Vertex Equality

While traversing a graph, I'd like to save the starting vertex, traverse a little further, and remove any vertices that have a specific edge back to this saved vertex.

This is my current attempt, but it obviously is not correct:

g.V().hasLabel('foo')
  .as('rule')
.repeat(out('belongs_to')).times(2)
.where(
  in('accepts').is(neq('rule'))
)

How can I check for vertex equality in Gremlin? How do I filter out all paths where such an equality exists?

Upvotes: 1

Views: 338

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

where() matches the start- and end-label, thus you can use where(in('accepts').as('rule')). And since you want to exclude those vertices that match the pattern, you need to negate this part using not().

g.V().hasLabel('foo').as('rule').
  repeat(out('belongs_to')).
    times(2).
  not(where(__.in('accepts').as('rule')))

Upvotes: 3

Related Questions