gremlin filter on Hashmap property without using a lambda

痴心易碎 提交于 2021-01-28 18:54:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!