问题
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' }
回答1:
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]
回答2:
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')
来源:https://stackoverflow.com/questions/48371627/gremlin-filter-on-hashmap-property-without-using-a-lambda