Given a set of vertices (say, for simplicity, that I start with one: G.V().hasId("something")
), I want to obtain all outgoing edges and their target vertices. I know that .out()
will give me all target vertices, but without the information about the edges (which have properties on them, too). On the other hand, .outE()
will give me the edges but not the target vertices. Can I obtain both in a single Gremlin query?
0
votes
2 Answers
1
votes
1
votes
Gremlin is as much about transforming graph data as it is navigating graph data. Typically folks seem to understand the navigation first which got you to:
g.V().hasId("something").outE()
You then need to transform those edges into the result you want - one that includes the edge data and it's adjacent vertex. One way to do that is with project()
:
g.V().hasId("something").outE()
project('e','v').
by().
by(inV())
Each by()
-modulator supplied to project()
aligns to the keys supplied as arguments. The first applies to "e" and the second to "v". The first by()
is empty and is effectively by(identity())
which returns the same argument given to it (i.e. the current edge in the stream).