I have the following Graph
If I write a Query g.V('A').Out(), how can I get that the values of the Edges which were traversed and the vertex which were encounterned in the traveral ?
You would need to tell Gremlin to not skip the edges. g.V().out()
is shorthand for g.V().outE().inV()
. In this case, you can interact with the value of the edges as you've explicitly told Gremlin to traverse them. I'll demonstrate with a few examples using the "modern" toy graph:
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
To start, you might want to filter on a particular edge property and then traverse to adjacent vertices:
gremlin> g.V().outE().has('weight',gt(0.5)).inV()
==>v[4]
==>v[5]
You mentioned in your question that you might want to see the values of edges and the vertices you encountered. One way would be to use path()
:
gremlin> g.V().outE().has('weight',gt(0.5)).inV().path()
==>[v[1],e[8][1-knows->4],v[4]]
==>[v[4],e[10][4-created->5],v[5]]
You might also get more explicit to get specific properties from the edge:
gremlin> g.V().outE().has('weight',gt(0.5)).inV().path().by().by('weight')
==>[v[1],1.0,v[4]]
==>[v[4],1.0,v[5]]