Reputation: 373
Hi I have recently started using Neo and wanted to know how I can query a graph to return two columns of IDs showing connections.
MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE s1.StartDate> '2015-01-01'
RETURN s1.StudentID, s2.StudentId
The above gives me all the connection for s1 however It doesn't show any other connections. How can I collect all of the connections in this graph into one edge list? The plan is to use this query in RNeo4j and analyse with igraph.
Thanks in advance
Upvotes: 1
Views: 1682
Reputation: 11216
If you are literally just interested in the pairs of nodes in each path then you could do something like the following.
This query takes the matched paths, groups the pairs of nodes in each path and then only returns the distinct pairs.
MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE s1.StartDate> '2015-01-01'
WITH REDUCE(pairs =[],r in relationships(path) | pairs + [[startNode(r).StudentId,endNode(r).StudentId]]) as pairs
UNWIND pairs as pair
WITH DISTINCT pair
RETURN pair[0] as from, pair[1] as to
Upvotes: 1
Reputation: 6514
The easiest way to do this is to return the path
MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE s1.StartDate> '2015-01-01'
RETURN path
As you are probably not interested in returning :FRIENDS relationship, because they are all the same you can return only nodes of the path
MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE s1.StartDate> '2015-01-01'
RETURN nodes(path)
You can find more functions for path in documentation.
Upvotes: 0