我有一个包含节点、关系、节点、关系的路径...集合。我想查找与此路径中的所有节点相关的节点。
有没有人能用Cypher给出查询示例?
现在我有
START startNode=node(3), endNode=node(5)
MATCH path=startNode-[:CONNECT*]->endNode
WITH path, relationships(path) AS connections, nodes(path) AS nodes
问题是,我不知道如何使用nodes集合来查找与该集合中的所有节点都有关系的节点。
我使用Neo4j 2.1.7和Node.js来构建REST。数据--大约70.000个节点和100.000个关系--包含许多小的连通子图。
一个API调用,例如localhost:8000/search?name=Bussum,应该返回名为Bussum的所有节点以及它们所属的连接组件。
说明:
(图片来源于)
我可以通过这样的查询获得所需的所有数据:
MATCH (a {name: "Bussum" })-[r*]-(b)
UNWIND rels AS rel
RETURN distinct startNode(rel) AS a, type(rel), endN
编辑我使用的是Neo4j 4.2.1
我需要一个Cypher查询来返回一个给定其根节点的完整树。所有节点和关系都必须在返回的集合中只提取和出现一次。这就是我要说的:
MATCH p = (n)-[*..]->(m)
WHERE id(n) = 0
WITH relationships(p) AS r
WITH distinct last(r) as rel
WITH [node IN [startNode(rel), endNode(rel)] | node] AS tmp, rel
UNWIND tmp AS node
RETURN collect(DISTINCT node) AS
例如,我在Neo4j中有以下图形 (startnode)-[:BELONG_TO]-(Interface)-[:IS_CONNECTED]-(Interface)-[:BELONG_TO]-
#the line below can repeat itself 0..n times
(node)-[:BELONG_TO]-(Interface)-[:IS_CONNECTED]-(Interface)-[:BELONG_TO]-
#up to the endnode
(endnode) 还有一个我也需要匹配的接口属性。我不想遵循所有的路径,我只想找到具有Interface Node属性的路径。
neo4j中的shortestPath( )函数是否使用where条件中提供的过滤条件?我的Cypher查询如下所示:
match (from:startNode{name:'START'}),(to:endNode{name:'END'}),
path = shortestPath(((from)-[:NESTED_JOIN|:REFERENCED_JOIN*1..10]-(to)))
WHERE NONE (n IN nodes(path) WHERE n.type= 'DEACTIVATED') return path