0
votes

I have a simple graph with two vertices, having ids 'a' and 'b'.

I have assigned an edge from 'a' to 'b' with label = 'foo'

gremlin> g.V()

==>v[b]

==>v[a]

gremlin> g.E()

==>e[04b4b9fd-2f20-751d-5673-5aa9d7ce0285][a-foo->b]

My question: how do I traverse backwards along the same edge? For example, if a query traverses to an outbound vertex, how can that query then traverse back across the same edge to the inbound vertex?

My query is shown below:

g.E('04b4b9fd-2f20-751d-5673-5aa9d7ce0285').outV().as('outV')...[want to get the inV for the same edge, here]

1

1 Answers

5
votes

There's a lot of different ways to do this. Here's a few that will hopefully inspire you to your answer. You probably shouldn't count on the order in which the vertices are returned in the following case, but you could do bothV():

gremlin> g.E(11).bothV()
==>v[4]
==>v[3]

To force order you could do a union():

gremlin> g.E(11).union(inV(),outV())
==>v[3]
==>v[4]

You could always project() your results:

gremlin> g.E(11).project('in','out').by(inV()).by(outV())
==>[in:v[3],out:v[4]]

If you need to do something with the outV() first and then come back to the edge after that to then traverse on inV() you could label the E() step with as():

gremlin> g.E(11).as('e').outV().hasLabel('person').select('e').inV()
==>v[3]

Hopefully, those examples help.