Returning specific properties from parent and children

19 views
Skip to first unread message

Joseph Duncan

unread,
May 24, 2022, 2:28:45 AM5/24/22
to Gremlin-users
I have a graph where some workers belongTo a workgroup and some workers lead a workgroup.  How do I write a query that returns some (but not all) properties of a workgroup, and also returns some (but not all) properties of the workers that blenong to that workgroup.  I have tried the following, but it returns all attributes for both vertex type in the relationship, but repeats all attributes for the workgroup with each worker:

g.V().haslabel('workgroup').has('workGroupID','xxxxx').as('wrkgrp')
   .repeat(inE('memberOf').outV().as('wrkr').simplePath()).emit().path().by(elementMap(true))

David Bechberger

unread,
May 25, 2022, 4:21:18 PM5/25/22
to Gremlin-users
Hello,

It is a bit unclear what exactly you are asking for here but I think you essentially have a tree where you want to return a different set of properties for the root versus the children.  If this is the case you can do this by using the project() step which would look something like this if you use the modern graph.

 gremlin> g.V(1).project('workgroup', 'worker').by(elementMap()).by(repeat(both().simplePath()).emit().dedup().elementMap().fold())
==>[workgroup:[id:1,label:person,name:marko,age:29],worker:[[id:3,label:software,name:lop,lang:java],[id:2,label:person,name:vadas,age:27],[id:4,label:person,name:josh,age:32],[id:6,label:person,name:peter,age:35],[id:5,label:software,name:ripple,lang:java]]]

In your example the query would look something like:
g.V().has('workgroup', 'workGroupID','xxxxx').project('workgroup', 'worker').
by(elementMap()).
by(repeat(in('memberOf').simplePath()).emit().dedup().elementMap().fold())


If this is not the case then if you could provide a sample script to create a small test graph as well as what you would like to see for results it would go a long way in helping us provide a better answer.

Thanks,
Dave

Reply all
Reply to author
Forward
0 new messages