How to retrieve all vertex with an label and nested vertex with edge to them?

32 views
Skip to first unread message

Augusto Will

unread,
Oct 11, 2017, 7:24:33 PM10/11/17
to Gremlin-users
I'm trying to retrieve all vertex with label "groups" and nested to them, the vertex that have an edge to "person". But I need all the properties or valueMap for "groups" and "persons", something like that:

"Group A" {permissionType: 4, name: 'Group A'}
-----"Person A" {Name: A, age: 28}
-----"Person B" {Name: B, age: 29}
-----"Person C" {Name: C, age: 30}
"Group B" {permissionType: 29, name: 'Group B'}
-----"Person D" {Name: D, age: 28}
-----"Person E" {Name: E, age: 29}
-----"Person F" {Name: F, age: 30}

Is possible to retrieve that vertex "groups" with them valueMaps and nest to them all the vertex with edge to that group, with all the ValueMaps of this vertex too?

Jason Plurad

unread,
Oct 11, 2017, 10:20:33 PM10/11/17
to Gremlin-users
Sounds like this is just a variation of the question you asked on Stack Overflow that Stephen already answered:

gremlin> graph = TinkerGraph.open(); g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin
> g.addV('group').property('name','Group A').property('permissionType', 4).as('ga').
......1>   addV('group').property('name','Group B').property('permissionType', 29).as('gb').
......2>   addV('person').property('name','Person A').property('age', 28).as('pa').
......3>   addV('person').property('name','Person B').property('age', 29).as('pb').
......4>   addV('person').property('name','Person C').property('age', 30).as('pc').
......5>   addV('person').property('name','Person D').property('age', 28).as('pd').
......6>   addV('person').property('name','Person E').property('age', 29).as('pe').
......7>   addV('person').property('name','Person F').property('age', 30).as('pf').
......8>   addE('contains').from('ga').to('pa').
......9>   addE('contains').from('ga').to('pb').
.....10>   addE('contains').from('ga').to('pc').
.....11>   addE('contains').from('gb').to('pd').
.....12>   addE('contains').from('gb').to('pe').
.....13>   addE('contains').from('gb').to('pf').iterate()

gremlin
> g.V().hasLabel('group').group().by(valueMap()).by(out('contains').valueMap().fold())

==>[[permissionType:[4],name:[Group A]]:[[name:[Person A],age:[28]],[name:[Person B],age:[29]],[name:[Person C],age:[30]]],[permissionType:[29],name:[Group B]]:[[name:[Person D],age:[28]],[name:[Person E],age:[29]],[name:[Person F],age:[30]]]]
Reply all
Reply to author
Forward
0 new messages