g.V(startVertex)
.repeat(__.inE().outV())
.until(__.hasId(targetVertex))
.path()
.by(T.label);
Im using Tinkerpop 3.6.1 in Java.
I get an timeout exception if between startVertex and targetVertex is no connection. To prevent this, according to https://tinkerpop.apache.org/docs/current/reference/#repeat-step I limited the repeat loop with .times(4)
between .until()
and .path()
.
g.V(startVertex)
.repeat(__.inE().outV())
.until(__.hasId(targetVertex))
.times(4)
.path()
.by(T.label);
But then it throws following exception:
org.apache.tinkerpop.gremlin.driver.exception.ResponseException: The repeat()-traversal was not defined: RepeatStep(until([HasStep([~id.eq(327684264)])]),null,emit(false))
I also tried .loops().is(4)
and placing both between .repeat()
and .until()
but that didn't change anything.
What else can I do?
Two things to be aware of:
simplePath
to avoid running "forever".until
and times
together, but you can use loops
. I have pasted an example of all this put together below. Note the second has
step I added. This is to handle the case where loops
is 4, but you did not find the desired target.g.V(startVertex)
.repeat(__.inE().outV().simplePath())
.until(__.hasId(targetVertex).or().loops().is(4))
.hasId(targetVertex)
.path()
.by(T.label);