0

I have a scenario like below, need to get the 'Application' label vertex properties and also, the id or property of the 'work' vertex that is connected to it

enter image description here

I have written the gremlin glv query to get the path and the Application properties, but struggling to get the properties of the vertex connected to it, (using pyton)

the query is,

g.V().hasLabel('Company').outE().inV().hasLabel('Person').outE().inV().hasLabel('Work').outE().inV().hasLabel('Applications').path().unfold().dedup().filter('Applications').elementMap().toList()

this return me the application vertex values like

[{
  id:'12159',label:'Applications', 'applicationname':'application1'
},
{
 id:'12157',label:'Applications', 'applicationname':'application2'
},
{
 id:'12155',label:'Applications', 'applicationname':'application3'
}

]

but we need to get the 'work' vertex details also along with the application details (applications can be connected to multiple work), like,

{
  id:'12159',label:'Applications', 'applicationname':'application1', 'workcode':['workcode1', 'workcode2']
},
{
  id:'12157',label:'Applications', 'applicationname':'application2', 'workcode':['workcode2']
}.
{
  id:'12157',label:'Applications', 'applicationname':'application3', 'workcode':['workcode2']
}

is it possible to get this information in gremlin itself or do we need to use python after getting the path,

the query to add is,

g.addV('Company').as('1').
addV('Company').as('2').
addV('Person').as('3').
addV('Work').as('4').
property(single, 'workcode', 'workcode2').
addV('Work').as('5').
property(single, 'workcode', 'workcode1').
addV('Application').as('6').
property(single, 'applicationname', 'application3').
addV('Application').as('7').
property(single, 'applicationname', 'application2').
addV('Application').as('8').
property(single, 'applicationname', 'application1').
addE('Contractor').from('2').to('3').
addE('Contractor').from('1').to('3').
addE('work').from('3').to('5').addE('work').
from('3').to('4').addE('workingon').from('4').
to('7').addE('workingon').from('4').to('6').
addE('workingon').from('5').to('8').
addE('workingon').from('4').to('8')

thank you

user1293071
  • 253
  • 1
  • 3
  • 14
  • Could you please provide a Gremlin script that creates some sample data - here is an example https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random all questions about Gremlin are easier to answer that way because you get a fully tested traversal as an answer. – stephen mallette Nov 27 '20 at 21:25
  • 1
    You can also use https://gremlify.com to do the exact same thing, but interactively – MorKadosh Nov 28 '20 at 08:56
  • thank you, I have added more details now – user1293071 Nov 29 '20 at 19:20
  • @stephenmallette, thank you, I have added the details now – user1293071 Nov 29 '20 at 19:21

1 Answers1

2

I don't think you should use path step since you are only using the last vertex. If you want to merge the element map with property from another vertex you can use project:

g.V().hasLabel('Company').outE().inV().
  hasLabel('Person').outE().inV().
  hasLabel('Work').outE().inV().
  hasLabel('Application').dedup().local(union(
      elementMap().unfold(),
      project('workcose').
        by(in().hasLabel('Work').
          values('workcode').fold())
    ).
    fold())

example: https://gremlify.com/d5wsk80nm2t/1

noam621
  • 2,766
  • 1
  • 16
  • 26
  • thanks, this is working when I need to join from the last node. Is the same logic can be applied if it not the last node also, I will try it out, thanks – user1293071 Dec 01 '20 at 12:41