I'm attempting to use gremlin through java/pipes and as one of my first queries I'm trying to find all nodes which are reachable from a given start node with a maximum distance of 3. In cypher my query is:
START n = node(*)
MATCH n -[*1..3]-> reached
WHERE (has(n.id) and n.id = \"v1\")
RETURN distinct n, reached
which works correctly, and what I have so far in gremlin is:
_().has('idd', 'v1').out().loop(1){it.loops < 3}{true}
which does not work correctly. From the way I understand it, it should emit the output from each iteration and iterate 3 times. At the moment I'm getting too few results.
Any help would be appreciated,
Thanks.
If your start node is g.v(1), then to find all unique nodes three steps away do:
g.v(1).out.loop(1){it.loops < 3}{true}.dedup
..you might have to make it < 4 (forget). Next, if your start node has idd=v1, then do:
g.V('idd','v1').out.loop(1){it.loops < 3}{true}.dedup
Be sure you have an index on idd or else that is a linear scan through all g.V for those vertices that have idd=v1.
HTH, Marko.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With