Looking for some guidance on a MATCH query

I have a fairly simple database with a V and E class. Vs are linked using Es. Es have one data field of “type”, which defines the type of the E that links two Vs.

In the scenario of V(1) -> E(type=X) -> V(2), the following MATCH statement works as expected (returning V(1) and V(2)):
MATCH {class:V, as:root, where:(key=1)}.outE("E"){where:(type="X")}.inV(){as:linked} RETURN $elements

But in the scenario of V(1) -> E(type=X) -> V(2) -> E(type=Y) -> V(3)..., I still get the same result:
MATCH {class:V, as:root, where:(key=1)}.outE("E"){where:(type IN ["X","Y"])}.inV(){as:linked} RETURN $elements

I’ve tried several variations of this MATCH statement, including adding a while in various places, but it either makes no difference or makes it worse. I’m looking for some suggestions on a MATCH statement that will traverse as many Vs as there are linking Es.

I’m running ODB 2.2.29.

Hi @eric24

Not sure I got it right, are you attempting to do a deep traversal or just a two-level traversal?

Looking at your pseudo-code, I’d say the correct query is this:

 MATCH 
   {class:V, as:root, where:(key=1)}.outE("E"){where:(type="X")}.inV(){as:linked}
   .outE("E"){where:(type="Y")}.inV(){as:linked2} 
RETURN $elements

but again, I’m not sure I got it completely…

Thanks

Luigi

Hi @luigidellaquila
Yes, I was trying to do a deep traversal. What you suggest works only if I know how many levels there are (and of course, I could easily expand it to include any fixed number of levels I want), but is there a syntax for following a set of links to an unknown depth (possibly with a depth limit)? The assumption would be that the Vs and Es are always the same classes and that the E type value(s) would be known.
–Eric

Hi @eric24

you can try the following:

MATCH {class:V, as:root, where:(key=1)}.(outE("E"){where:(type="X" OR type="Y")}.inV()){as:linked, while:($depth < 3)} RETURN $elements