Search code examples
aggregategremlingremlinnet

Group Neighbors by Outgoing Edge Type and Add Self to Result List


I want a result like this:

[
 {
  "vertex": [ the_vertex_itself ]
 },
 {
  "outgoingEdgeGroup1": [ list_of_outgoing_neighbors_with_edge_type_outgoingEdgeGroup1 ]
 },
 {
  "outgoingEdgeGroup2": [ list_of_outgoing_neighbors_with_edge_type_outgoingEdgeGroup2 ]
 }
]

I'm able to get this:

[
 {
  "outgoingEdgeGroup1": [ list_of_outgoing_neighbors_with_edge_type_outgoingEdgeGroup1 ]
 },
 {
  "outgoingEdgeGroup2": [ list_of_outgoing_neighbors_with_edge_type_outgoingEdgeGroup2 ]
 }
]

With the following query:

g.V('{unitId}').outE().group().by(label()).by(inV().fold())

But how would I append on the target vertex itself?


Solution

  • One way is just to use a union. If you need a more complete key/value type of structure that can be created also by adding project steps or nested group steps.

    Using the air-routes data set:

    gremlin> g.V(44).union(identity().values('city'),inE().group().by(label()).by(outV().fold())).fold()
    
    ==>[Santa Fe,[contains:[v[3742],v[3728]],route:[v[13],v[31],v[20],v[8]]]]