Reputation: 13
Can anyone help with graph transverse using gremlin .I have connected graph data were i need to query user contact with relationship 'KNOWS' and its outgoing connection vertices properties .
g.addV().property(id, 'user').as('user').
addV().property(id, 'user1').as('user1').
addV().property(id, 'user2').as('user2').
addV().property(id, 'user3').as('user3').
addV().property(id, 'user4').as('user4').
addV().property(id, 'Industry1').as('Industry1').
addV().property(id, 'Industry2').as('Industry2').
addV().property(id, 'skills1').as('skills1').
addV().property(id, 'skills2').as('skills2').
addE('KNOWS').from('user').to('user1').
addE('KNOWS').from('user').to('user2').
addE('KNOWS').from('user').to('user3').
addE('KNOWS').from('user').to('user4').
addE('WORKS').from('user1').to('Industry1').
addE('WORKS').from('user2').to('Industry1').
addE('WORKS').from('user2').to('Industry2').
addE('WORKS').from('user3').to('Industry2').
addE('SKILLEDIN').from('user3').to('skills1').
addE('SKILLEDIN').from('user4').to('skills1').
addE('SKILLEDIN').from('user4').to('skills2')
What is required- navigating from user node get all outgoing connection with relationship 'KNOWS' and for each connection get his industry and skills The output should be traversal result from user
user1---Industry1,skills1 user2--Industry1,Industry2 user3--Industry3,skills1 user4--skills1,skills2
Upvotes: 1
Views: 210
Reputation: 46216
I think this is the output you want:
gremlin> g.V('user').out('KNOWS').
......1> group().
......2> by(id).
......3> by(project('industries','skills').
......4> by(out('WORKS').id().fold()).
......5> by(out('SKILLEDIN').id().fold()))
==>[user1:[industries:[Industry1],skills:[]],user2:[industries:[Industry1,Industry2],skills:[]],user3:[industries:[Industry2],skills:[skills1]],user4:[industries:[],skills:[skills1,skills2]]]
Upvotes: 1