简体   繁体   English

如何在neo4j中搜索连接到特定顶级节点的所有节点和关系

[英]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.

相关问题 Neo4j:检索连接到Neo4j Rest中的节点或通过Cypher的所有节点和关系 - Neo4j : Retrieving All Nodes and Relationship connected to a Node in Neo4j Rest OR through Cypher 如何在Neo4j的Cypher中获取连接到集合中每个其他节点的节点? - How to get in Neo4j's Cypher the nodes that are connected to every other node within a set? 在neo4j中删除具有其关系的多个节点 - Delete multiple nodes with their relationships in neo4j 从neo4j返回NodeEntity不包含关系或连接的节点 - Returning a NodeEntity from neo4j doesn't contain relationships or connected nodes 如何删除neo4j图中的所有关系? - How to delete all relationships in neo4j graph? 如何删除节点以及所有相关节点不仅关系— neo4j cypher 1.8 - how to delete node and all related nodes not only the relations — neo4j cypher 1.8 使用neo4j找到与给定节点有关系的节点集的有效方法 - Efficient way to find node set having relationships to given nodes using neo4j 如何在 Spring Data Neo4j 中获取节点及其所有子节点 - How to fetch nodes and all their children in Spring Data Neo4j 使用 java 从 neo4j 获取所有图形数据,包括节点和关系到 hashmap - get all graph data including nodes and relationships from neo4j using java into a hashmap Neo4j密码跟踪删除节点/关系 - Neo4j cypher keeping track of delete Nodes/relationships
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM