Query
g.withSack(0).V().hasLabel('A').has('label_A','A').union(__.emit().repeat(sack(sum).by(constant(1)).in()),emit().repeat(sack(sum).by(constant(-1)).out())).project('level','properties').by(sack()).by(tree().by(valueMap().by(unfold())).unfold().unfold())
Output
[
{
"level": 0,
"properties": {
"key": {
"label_A": "A"
},
"value": {}
}
},
{
"level": 1,
"properties": {
"key": {
"label_A": "A"
},
"value": {
"{label_B="B"}": {}
}
}
},
{
"level": 2,
"properties": {
"key": {
"label_A": "A"
},
"value": {
"{label_B=B}": {
"{label_C=C}": {}
}
}
}
},
The query only returns the properties of nodes. Please modify the query so that it returns properties of nodes as well as relations respectively in tree format.