0

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')

Zhongmin
  • 1,684
  • 1
  • 16
  • 33

2 Answers2

1

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]]  
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • thanks Kelvin, it works! I thought I need to use 'where', but just don't know how exactly it should be, nice. – Zhongmin Mar 26 '21 at 22:13
-1
g.V().has('A', 'tag', 'key1').
  out('e').
  has('B', 'n', '123')

The first line filters by the label "A" and the property "tag" == "key1". The second line makes the Gremlin go out along the "e" edge. And it will land on the adjacent vertex. The third line filters by the label "B" and the property "n" == "123"

Bassem
  • 2,736
  • 31
  • 13