In this MATCH query, we are using Variable Length Edges. If there is a scenario where you have lets say vertex A (vertex has a property 'name' whose value is 'A') that has an edge with vertex B which has an edge with vertex C
A -> B -> C
This means there is a variable length edge between A and C. To query such an edge, you could formulate the following query:
SELECT * FROM cypher('graph_name', $$
MATCH p = (a: Vertex{name : 'A'})-[e: EDGE]->(b: Vertex{name : 'B'})-[e1: EDGE]->(c: Vertex
{name: 'C'})
RETURN p
$$) AS (path agtype);
And it would output the path (path is simply a traversal from one vertex to another and would contain all the vertices and the edges connecting the vertices)from vertex A to C with all the edges in between.
But, another way to query such an edge is using a more compact form and that is
SELECT * FROM cypher('graph_name', $$
MATCH p = (a: Vertex {name : 'A'})-[e: EDGE*2]->(c: Vertex {name : 'C'})
RETURN p
$$) AS (path agtype);
Here *2
means you want to travel only 2 edges from A.
This also outputs the path from Vertex A to Vertex C with the two edges and one vertex it has traversed while going from A to C.
Coming to the query you have given, you are matching all the paths that start from
(actor {name: 'Willam Defoe'})
and end at
(co_actor)
That means all the paths that originate from any vertex with the property name: 'William Defoe'
which is connected to a vertex with edge label 'ACTED_IN' and that vertex is connected with another vertex with label 'ACTED_IN' will be matched
I hope it helps!