Getting the vertex and the details of the vertex connected to it

135 views Asked by At

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

1

There are 1 answers

1
noam621 On BEST ANSWER

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