简体   繁体   English

在Neo4j密码中获取不涉及某些关系的可变长度路径

[英]Getting variable length paths not involving certain relationships in neo4j cypher

I know there is a node type (a:Source) which will have outgoing edge of type [:RefRel] on some other node (x) . 我知道有一个节点类型(a:Source)在其他某个节点(x)上将具有[:RefRel]类型的传出边缘。 I want to get all other paths between (a) and (x) which involve at least one node between them. 我想获得(a)(x)之间的所有其他路径,这些路径之间至少涉及一个节点。

Consider my graph is as follows: 考虑我的图如下:

在此处输入图片说明

The query should return two paths: abcd and abce . 该查询应返回两个路径: abcdabce The nodes and relationships on these path can be of any type. 这些路径上的节点和关系可以是任何类型。

Creating graph with cypher: 用密码创建图形:

CREATE (a:Source)-[:RelA]->(b)-[:RelB]->(c)-[:RelC]->(d)
CREATE (c)-[:RelD]->(e)
CREATE (a)-[:RefRel]->(d)
CREATE (a)-[:RefRel]->(e)

I wrote query as follows: 我写的查询如下:

MATCH (a:Source)-[:RefRel]-(b)
MATCH path=(a)-[*2..]-(b)      //2.. because that means at least one node on the path
RETURN path

But it returned whole graph. 但是它返回了整个图。 When I checked the rows, it returned a lot of them due to cycles in the graph. 当我检查行时,由于图中的循环,它返回了很多行。

So included the filter in the query as follows: 因此在查询中包括了过滤器,如下所示:

MATCH (a:Source)-[:RefRel]-(b)
MATCH path=(a)-[c*2..]-(b)
WHERE filter(rel IN c WHERE rel.name<>"RefRel")
RETURN path

But then it returned nothing. 但是随后它什么也没返回。 Whats wrong here? 怎么了

None of the relationships you created have a "name" property. 您创建的关系都没有“名称”属性。 Relationships have types, and this is not a property. 关系具有类型,这不是属性。 You want to use 你想用

type(rel) <> "RefRel"

Also, on your WHERE, it may be better to use ALL() instead of FILTER(). 另外,在您的WHERE上,最好使用ALL()而不是FILTER()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM