Here\'s a really simple query:
g.V(\'customerId\').out().path()
The JSON output of this is
{
\"requestId\":\"96b26c1d
You should always specific exactly the data that you want returned in a traversal. Even for something as simple as:
g.V('customerId')
you should really prefer:
g.V('customerId').valueMap('name','age')
It's really no different in SQL where you likely wouldn't do
SELECT * FROM customer
but instead
SELECT name, age FROM customer
As for your question, you just need to specify the data you want back, so use the by()
modulator for the path()
:
g.V('customerId').
out().
path().
by(valueMap('name','age'))
That of course assumes your out()
is also a "customer", if not, just add a second by()
with the specific fields required for that. The by()
modulators are applied in round-robin fashion. If you'd like a slightly cleaner bit of JSON to deal with you might instead use project()
like:
g.V('customerId').
out().
path().
by(project('name','age').
by('name').
by('age'))
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.
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]