Used following gremlin query to match exactly 1 -> 3 -> 5 path
g.V().match(
as('x0').has('parent', 'state', 1),
as('x0').repeat(out()).emit().has('parent', 'state', 3).as('x1'),
as('x1').out().has('parent', 'state', 5).as('x2')
).
select('x0', 'x1', 'x2')
Instead of using repeat + until, I am now using repeat +emit to find all paths and select one which have state=3
This matcher doesn't stop matching when finding first 3 but continues. For my use case, cyclic paths cannot happen and the graphs sizes are very small (<100 vertices) so the query should work fine (without until).