albertlockett
albertlockett

Reputation: 204

gremlin filter on Hashmap property without using a lambda

If I have a vertex in a graph database where one of the properties is a map, is there a way to filter on properties of the map without using a lambda?

Create the vertex like this:

gremlin> v = graph.addVertex(label, 'LABEL')
==>v[68]
gremlin> g.V(68).property('prop', [ key: 'val' ])
==>v[68]
gremlin> g.V(68).valueMap()
==>{prop=[{key=val}]}

Is there a way to filter for vertices by prop.key == 'val' without using a lambda?

 gremlin> g.V().filter{ it.get().values('prop').next().get('key') == 'val' }

Upvotes: 1

Views: 964

Answers (2)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

Here you go:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('LABEL').
......1>     property('prop', [ key: 'val' ]).
......2>   addV('LABEL').
......3>     property('prop', [ key: 'val2' ]).iterate()
gremlin> g.V().valueMap(true)
==>[prop:[[key:val]],id:0,label:LABEL]
==>[prop:[[key:val2]],id:2,label:LABEL]
gremlin> g.V().filter(values('prop').select('key').is('val'))
==>v[0]
gremlin> g.V().filter(values('prop').select('key').is('val2'))
==>v[2]

Upvotes: 3

bechbd
bechbd

Reputation: 6341

If all you are trying to do is find all vertices that have 'prop'='val' you can do this using the gremlin has step (documentation here) and your query would look like this:

g.V().has('prop', 'val')

Upvotes: 0

Related Questions