My use case is: Bag
vertex has edge holds
to Box
vertex and Box
vertex has edge contains
to Fruit
vertex. So it's a parent-child relation between 3 vertices.
Is it possible to write gremlin query which returns all related 3 vertices. for e.g i need to fetch all Bags by id
including Box
vertex and further down to Fruit
vertex for that Bag id. In SQL like syntax it's a simple select * from bag where id = 1
.
sample structure:
g.addV('bag').property('id',1).property('name','bag1').property('size','12').as('1').
addV('box').property('id',2).property('name','box1').property('width','12').as('2').
addV('fruit').property('id',3).property('name','apple').property('color','red').as('3').
addV('bag').property('id',4).property('name','bag2').property('size','44').as('4').
addV('box').property('id',5).property('name','box2').property('width','14').as('5').
addV('fruit').property('id',6).property('name','orange').property('color','yellow').as('6').
addE('holds').from('1').to('2').
addE('contains').from('2').to('3').
addE('holds').from('4').to('5').
addE('contains').from('5').to('6').iterate()
I want to get all properties of 1
, 2
, 3
when i query for vertices 1
.
I want the response in the below format.
"bags" : [{
"id":"1",
"name":"bag1",
"size" :"12",
"boxes":[ {
"id" : "2",
"name":"box1",
"width" : "12",
"fruits": [{
"id":"3",
"name" : "apple",
"color" : "red"
}]
}]
},
{
"id":"4",
"name":"bag2",
"size" : "44",
"boxes":[ {
"id" : "5",
"name":"box2",
"width" : "44",
"fruits": [{
"id":"6",
"name" : "orange"
"color" : "yellow"
}]
}]
}]
But not sure if similar case is possible in gremlin as there are no implicit relation between vertices.