Reputation: 181
I have started using neo4j and I have several versions of a graph in my neo4j database (the only thing that changes is the timestamp at the top node).
I was wondering how to get only the relations to that one node. I currently use this:
"START n=node(*) MATCH (n)-[r]->(m) RETURN n,r,m;"
But this just displays all of them. I know I have to change the n=node(*) but I don't know to what. (the name of the top node is: Info) so maybe something like
"START n=node(i:Info{timeStamp:'20/04/2018'}) MATCH (n)-[r]->(m) RETURN n,r,m;"
but that would just give me the relations to that one node... and I need the whole graph
Upvotes: 1
Views: 130
Reputation: 66989
Do this:
MATCH (n:Info)-[r]->(m)
WHERE n.timeStamp = '20/04/2018'
RETURN n, r, m;
For quicker access to the top node, you should also create an index on :Info(timeStamp)
:
CREATE INDEX ON :Info(timeStamp);
[UPDATED]
To also get all the relationships and nodes to depth 2, you could do this:
MATCH (n:Info)-[r1]->(m1)-[r2]->(m2)
WHERE n.timeStamp = '20/04/2018'
RETURN n, r1, m1, r2, m2;
To get all the relationships and nodes up to an arbitrary depth (say, 5), you can do this (each returned path
will be one of the matching paths from n
to a child node):
MATCH path=(n:Info)-[r*..5]->(m)
WHERE n.timeStamp = '20/04/2018'
RETURN path;
You could also just use [r*]
for an unbounded variable-length search, but that can cause the server to run out of memory or take an extremely long time to finish.
Upvotes: 1