Wen*_*att 3 gremlin tinkerpop amazon-neptune
这是一个非常简单的查询:
g.V('customerId').out().path()
Run Code Online (Sandbox Code Playgroud)
这个的 JSON 输出是
{
"requestId":"96b26c1d-d032-2004-d36e-c700bd6db2a2",
"status":{
"message":"",
"code":200,
"attributes":{
"@type":"g:Map",
"@value":[
]
}
},
"result":{
"data":{
"@type":"g:List",
"@value":[
{
"@type":"g:Path",
"@value":{
"labels":{
"@type":"g:List",
"@value":[
{
"@type":"g:Set",
"@value":[
]
},
{
"@type":"g:Set",
"@value":[
]
}
]
},
"objects":{
"@type":"g:List",
"@value":[
{
"@type":"g:Vertex",
"@value":{
"id":"customerId",
"label":"customer"
}
},
{
"@type":"g:Vertex",
"@value":{
"id":"e:customerIdemail@email.com",
"label":"email"
}
}
]
}
}
}
]
},
"meta":{
"@type":"g:Map",
"@value":[
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,客户顶点还包含属性名称和年龄。我想了解的是如何(如果可能的话)形成我的 gremlin 查询,以便它在图中嵌套顶点属性。请注意,当我只运行 gV("customerId") 时,响应确实包含这些属性。
ste*_*tte 12
您应该始终准确地指定要在遍历中返回的数据。即使对于像这样简单的事情:
g.V('customerId')
Run Code Online (Sandbox Code Playgroud)
你应该更喜欢:
g.V('customerId').valueMap('name','age')
Run Code Online (Sandbox Code Playgroud)
在您可能不会做的 SQL 中,这真的没有什么不同
SELECT * FROM customer
Run Code Online (Sandbox Code Playgroud)
但反而
SELECT name, age FROM customer
Run Code Online (Sandbox Code Playgroud)
至于你的问题,你只需要指定你想要的数据,所以使用by()调制器path():
g.V('customerId').
out().
path().
by(valueMap('name','age'))
Run Code Online (Sandbox Code Playgroud)
当然,假设您out()也是“客户”,如果不是,只需添加第二个by()所需的特定字段。该by()调制器以循环的方式应用。如果你想要一个稍微干净一点的 JSON 来处理,你可以使用project()像:
g.V('customerId').
out().
path().
by(project('name','age').
by('name').
by('age'))
Run Code Online (Sandbox Code Playgroud)
因为这将消除valueMap()添加到正确解释多属性的嵌入式列表。
从 TinkerPop 3.4.4 开始,您还可以考虑 -step,elementMap()其中包含更多图元素的结构。
gremlin> g.V().has('person','name','marko').elementMap()
==>[id:1,label:person,name:marko,age:29]
gremlin> g.V().has('person','name','marko').elementMap('name')
==>[id:1,label:person,name:marko]
gremlin> g.V().has('person','name','marko').properties('name').elementMap()
==>[id:0,key:name,value:marko]
gremlin> g.E(11).elementMap()
==>[id:11,label:created,IN:[id:3,label:software],OUT:[id:4,label:person],weight:0.4]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7323 次 |
| 最近记录: |