[英]How to search for all nodes and relationships connected to a specific top node in neo4j
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). 我已经开始使用neo4j,并且在neo4j数据库中有几种版本的图形(唯一更改的是顶部节点的时间戳)。
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. 我知道我必须更改n = node(*),但我不知道要做什么。 (the name of the top node is: Info) so maybe something like (顶部节点的名称是:Info),所以也许像
"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 但这只会给我与该节点的关系...而我需要整个图
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)
: 为了更快地访问顶层节点,您还应该在:Info(timeStamp)
上创建一个索引 :
CREATE INDEX ON :Info(timeStamp);
[UPDATED] [更新]
To also get all the relationships and nodes to depth 2, you could do this: 还要使所有关系和节点都到达深度2,可以执行以下操作:
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): 要使所有关系和节点达到任意深度(例如5),您可以这样做(每个返回的path
都是从n
到子节点的匹配路径之一):
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. 您也可以只使用[r*]
进行无限制的可变长度搜索,但这可能会导致服务器内存不足或花费很长时间才能完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.