我有以下在 CosmosDB 中成功运行的 Gremlin 查询:
g.addV('person').property(id, 'grand_father').property('name', 'Grand Father')
g.addV('person').property(id, 'father').property('name', 'Father')
g.addV('person').property(id, 'child').property('name', 'Child')
g.V('grand_father').addE('father_of').to(V('father'))
g.V('father').addE('father_of').to(V('child'))
我运行了g.V('grand_father').repeat(out()).emit().tree()
生成以下输出的查询:
[
{
"grand_father": {
"key": {
"id": "grand_father",
"label": "person",
"type": "vertex",
"properties": {
"name": [
{
"id": "2b687c65-6490-4846-a5ef-1b7d67e51916",
"value": "Grand Father"
}
]
}
},
"value": {
"father": {
"key": {
"id": "father",
"label": "person",
"type": "vertex",
"properties": {
"name": [
{
"id": "c1f75463-8aa5-4c15-854d-88be0ec9cdc9",
"value": "Father"
}
]
}
},
"value": {
"child": {
"key": {
"id": "child",
"label": "person",
"type": "vertex",
"properties": {
"name": [
{
"id": "d74d6286-5fa9-4b90-9619-1f173d5da53e",
"value": "Child"
}
]
}
},
"value": {}
}
}
}
}
}
}
]
我想再次对上面的 GraphSON 树进行变换,生成如下格式的自定义层次树。
{
"person":{
"name":"Grand Father"
},
"children":[
{
"person":{
"name":"Father"
},
"children":[
{
"person":{
"name":"Child"
}
}
]
}
]
}
g.V('grand_father').repeat(out()).emit().tree()
为了达到这个结果,我需要做出哪些改变?