首页 > 解决方案 > Get all nodes with relationships

问题描述

Tree structure

I want a query in which if I send Name: "Johnson" it should all nodes that are directly and indirectly connected in a data format shown in the image. How would I query to get all connected nodes in data format with relationship between primary node and related node?

标签: neo4j

解决方案


您可以使用可变长度的关系模式。

例如,要从名为“Johnson”的人(我认为它是唯一的)到每个亲戚获取所需的路径:

MATCH path = (p:Person)-[:Father|Mother|Son|daughter|Wife *]-(:Person)
WHERE p.name = 'Johnson'
RETURN path

推荐阅读