testing data as below:
g.addV('A').property('name','n').property('tag','key1');
g.addV('B').property('n','123');
g.addV('A').property('name','m').property('tag','key2');
g.addV('B').property('m','321')
g.V().hasLabel('A').addE('e').to(g.V().hasLabel('B'));
Given 'key1' and '123', how do I get the 1st B vertex?
I have tried below query, it does not work
g.V().hasLabel('B').as('B').inE('e').outV().has('tag','key1').as('A').select('B').has(select('A').values('name'),'123')
You need to use a slightly different approach and replace has
with a where
step. It is confusing that the has
step seems as if it should be able to accept an arbitrary traversal and yield its value. In fact all that happens is that if a traversal inside a has
yields any result it is treated as "true".
gremlin> g.V().hasLabel('A').
......1> has('tag','key1').as('A').
......2> out('e').
......3> where(valueMap().select(select('A').values('name')).unfold().is('123')).
......4> valueMap(true)
==>[id:60872,label:B,n:[123]]