Let's say I have a query like:
select out("E1").out("E2").out("E3") from V1
where E1, E2, E3 are classes extending "E" and V1 is a class extending "V".
I would like to get all elements that were traversed at the execution of the query (i.e. not only the end results). Consider it as a kind of tracing of the elements that were involved at the execution of the query.
I tried the following traverse command:
traverse in from (traverse outE("E3") from (traverse in from (traverse outE("E2") from (traverse in from (traverse outE("E1") from V1)))))
which is close to what i need but it is not the same. The problem with this command is that if some vertices of the initial set of "V1" contain edges of the class "E2" or "E3", then they will be traversed as well even though I do not want them to be traversed (since the select query will traverse the "E2" edges of the vertices that were returned by the traversing of the "E1" edges only) That is, I would like to have the TRAVERSE command to traverse only the results of the previous step and not all the results upto that point
Is there a way to achieve this?
You should use MATCH instead:
MATCH
{class:V1, as:a} -E1-> {as:b} -E2-> {as:c} -E3-> {as:d}
RETURN $patterns
This will return all the RIDs that match the pattern, eg.
| a | b | c | d |
| #12:0 | #12:1 | #12:2 | #12:4 |
| #12:3 | #12:5 | #12:7 | #12:8 |
If you need them expanded, just replace return $patterns
with return $elements
, eg.
MATCH
{class:V1, as:a} -E1-> {as:b} -E2-> {as:c} -E3-> {as:d}
RETURN $elements