I have a working opencypher query but due to some reason I have to go with gremlin.
Query
MATCH (:Account {name: 'account.b'})-[:RESULTS_FROM|DEPENDS_ON*]->(n:Account)
RETURN n
I tried to write gremlin equivalent of it but it's not working as expected.
g.V().has('name', 'account.b').hasLabel('Account')
.repeat(both('RESULTS_FROM', 'DEPENDS_ON').hasLabel('Account')).emit()
.dedup()
How can I achieve the same behavior using gremlin.
Try something like this. As the Cypher query is unbounded by number of hops, a
repeat...until
should work. I left thededup
in but in your Cypher query I do not see aDISTINCT
so this may still give different answers. I changedboth
toout
, as your Cypher query has a direction specifiied.If there are cycles in the graph and you want to avoid visiting the same node twice for a given path, you can add a
simplePath()
after theout()
as follows.