I have a TinkerPop Graph on a Gremlin Server and I'm trying to recursively search up a tree from a leaf until I can get to the root.
Given a tree that looks like this
I can query Items and Packages off of a known Shipment via this.
g.V("MyShipment").repeat(out().not(hasLabel("contracted", "contains")).simplePath()).until(outE().count().is(0)).path()
However trying to do the reverse fails
g.V("MyItem2").repeat(in().not(hasLabel("contracted", "contains")).simplePath()).until(inE().count().is(0)).path()
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script61.groovy: 1: unexpected token: in @ line 1, column 23. g.V("MyItem2").repeat(in().not(hasLabel("contracted","contains")).simplePath()).until(inE().count().is(0)).path() ^
1 error
Is there anyway to recursively look up a tree via In Edges?
The in
keyword is a reserved word in Groovy. Try using
g.V("MyItem2").
repeat(__.in().not(hasLabel("contracted","contains")).simplePath()).
until(inE().count().is(0)).
path()
Note that you can also write the query as
g.V("MyItem2").
repeat(__.in().not(hasLabel("contracted","contains")).simplePath()).
until(__.not(__.in())).
path()