如何检索多个深度关系的节点Neo4j Database Cypher? [英] How to retrieve nodes for multiple depth relationships Neo4j Database Cypher?
问题描述
假设有一个简单的图形,如下所示,
Assuming that there is a simple graph as follows,
(City {name:gotham})<-[:LOCATED]-(Tower {name:abc})<-[:LOCATED]-(Bank:{name:CityBank})
(City {name:gotham})<-[:LOCATED]-(Cinema {name:MainHall})
(City {name:gotham})<-[:LOCATED]-(Bank {name:ComBank})
我如何在Neo4j数据库中获取名为Gotham的城市中的所有银行(包括CityBank和comBank)?我尝试按照以下模式进行操作,它返回了位于城市哥顿的所有节点(包括电影院)
How can i get all banks located in City named Gotham in Neo4j Database (including CityBank and comBank)? I tried following pattern, it returned all the nodes LOCATED in City named gotham (Including Cinema as well)
MATCH (City{name:'Gotham'})<--(Bank) RETURN Bank
推荐答案
假设您刚刚键入错误的查询,什么不起作用?
Assuming you just mistyped the query, what isn't working?
MATCH (:City{name:'Gotham'})<--(bank:Bank) RETURN bank
应该可以正常工作.
should work fine.
完全错误输入,应该已经读过(孤独的星号表明,任何类型的所有关系,任何长度的路径):
Completely wrong as typed, should have read (the lonely star indicating, all relationships of any type, any length path):
MATCH (:City{name:'Gotham'})<-[*]-(bank:Bank) RETURN bank
更好的是:
MATCH (:City{name:'Gotham'})<-[:LOCATED*1..2]-(bank:Bank) RETURN bank
因此仅遍历LOCATED
关系.您可以调整*1..2
(匹配长度为1到2的路径)以满足路径长度要求(例如,如果添加了Street或Block节点,则可能要匹配长度为3 *1..3
的路径)
So as only to traverse LOCATED
relationships. You can adjust the *1..2
(match paths of length 1 to 2) to meet path length requirements (if for example you added a Street or Block node, you might want to match paths up to length 3 *1..3
)
这篇关于如何检索多个深度关系的节点Neo4j Database Cypher?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!