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:
..you might have to make it < 4 (forget). Next, if your start node has idd=v1, then do:
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.