Here's a really simple query:
g.V('customerId').out().path()
The JSON output of this is
{
"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":[
]
}
}
}
Now, a customer vertex also contains the property name and age. What I would like to understand, is how to (simply, if possible) form my gremlin query such that it nests of the vertex properties within the graph. Note that when I just run g.V("customerId"), the response does contain these properties.
You should always specific exactly the data that you want returned in a traversal. Even for something as simple as:
you should really prefer:
It's really no different in SQL where you likely wouldn't do
but instead
As for your question, you just need to specify the data you want back, so use the
by()
modulator for thepath()
:That of course assumes your
out()
is also a "customer", if not, just add a secondby()
with the specific fields required for that. Theby()
modulators are applied in round-robin fashion. If you'd like a slightly cleaner bit of JSON to deal with you might instead useproject()
like:as that will kill out the embedded lists that
valueMap()
adds in to properly account for multi-properties.As of TinkerPop 3.4.4, you would also consider
elementMap()
-step which includes more of the structure of the graph element.