[英]Neo4j cypher: find node at detph 2, without circular path
I would like to find all nodes at distance 2 from the current node: 我想找到距离当前节点2的所有节点:
eg:
1<->2
2<->3
1->3
2->4
A of this kind from node 1, should find node 4 来自节点1的这种A应该找到节点4
I've tried this query, but it is suffering of circular paths: 我已经尝试过此查询,但是它遇到了循环路径:
start n=node({startid})
match n--> m
with distinct m as f1
match f1-->m
with distinct m as f2
return count(f2)
in fact, it finds also 1,2,3,4 as node at distance 2, without considering that 1 should be at distance 0, 2,3 distance 1, and only 4 is at distance 2. 实际上,它还在距离2处找到了1,2,3,4作为节点,而没有考虑距离1应该在距离0、2,3距离1上,而只有4在距离2处。
any advice? 有什么建议吗?
Do you mean something like this: 您的意思是这样的吗:
START n=node({startid})
MATCH (n)-[*..2]->m
RETURN m
After the * you can define the length of the path. *之后,您可以定义路径的长度。 *..2 means: Length between zero and 2.
* .. 2表示:长度在零到2之间。
START n=node({startid})
MATCH (n)-[*2]->m
WHERE n <> m
RETURN m
For fix length 2 and the WHERE will make sure n is not returned. 对于固定长度2,WHERE将确保不返回n。
For the full documentation: http://docs.neo4j.org/chunked/milestone/query-match.html#match-variable-length-relationships 有关完整的文档,请访问: http : //docs.neo4j.org/chunked/milestone/query-match.html#match-variable-length-relationships
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.