Reputation: 3063
How can i request with gremlin a limited list of nodes with properties of my choosing?
Something like:
g.V. 10 nodes with nodeType=="User", return only id, name and email.
Upvotes: 1
Views: 215
Reputation: 3456
Using TinkerPop 3+, that would be:
g.V().hasLabel('user').limit(10).valueMap(true, 'name', 'email')
Calling valueMap(true)
returns both the id
and the label
of the traversed graph element.
For performance, it is now recommended to avoid lambdas and use Gremlin steps.
Upvotes: 2
Reputation: 14391
If you are using Tinkerpop 3 and you have the "Type" you are are searching on defined as the node label then you can do something like this:
g.V.hasLabel('User')[0..10].valueMap.select('id','name','e-mail')
Note also that I think you need to specify [0..10] if you want 10 nodes and not [0..9]
However I totally defer to Marko's answer on performance as he understands the internals. I just like the clean feel of hasLabel().
Upvotes: 0
Reputation: 1702
For speed, do filter{it.getProperty('nodeType').equals('User')}...
Upvotes: 2
Reputation: 634
g.V.filter{it.nodeType=='User'}[0..9].transform(){it.id + ' ' + it.name + ' ' + it.email}
Upvotes: 0