0

I have a not so complex set of data, but I am struggling to make a query.

Let's say that I have a main vertex with id 1. That vertex has edges to vertices 10, 11, and 12. Each of those vertices have edges to 100 and 101.

If I do something like this:

g.V(1).inE('type').project('e', 'v').by().by(outV().valueMap())

I get a list of vertices: 10, 11 and 12, but I don't get the list of 100 and 101. I assume that I can do something with coalesce or something, but I can't figure out the proper way of doing this.

Also, down the line I want to filter the 10, 11 and 12 vertices based on one 100 and 101 property. Meaning that if 100 has a property like x = 1 and 101 has a property x = 2, I want to get only the vertices (in the 10-12 set) that point to the vertex that has x = 1.

E.T
  • 1,095
  • 1
  • 10
  • 19

1 Answers1

1

Assuming you do not want all the paths and just all of the relevant vertices visited you can do something like this.

gremlin> g.addV().property(id,'1').as('1').
......1>   addV().property(id,'10').as('10').
......2>   addV().property(id,'11').as('11').
......3>   addV().property(id,'12').as('12').
......4>   addV().property(id,'100').property('p',1).as('100').
......5>   addV().property(id,'101').property('p',2).as('101').
......6>   addE('link').from('1').to('10').
......7>   addE('link').from('1').to('11').
......8>   addE('link').from('1').to('12').
......9>   addE('link').from('10').to('100').
.....10>   addE('link').from('11').to('101')
==>e[61381][11-link->101]

gremlin> g.V('1').out().store('a').out().has('p',2).store('a').cap('a').dedup()
==>[v[10],v[11],v[12],v[101]]  
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • Thank you! Now I have to understand what you did. Didn't know about the store() function so I'm going to have to read about it. – E.T Jul 24 '21 at 23:34