如何在neo4j中找到第二级连接? [英] how to find 2nd level of connections in neo4j?

查看:155
本文介绍了如何在neo4j中找到第二级连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的neo4j图如下所示..
300 连接到 100 100 连接到 201 400 .
我想找出neo4j中的第二级连接. 例如: 300 的第二级节点应返回 201 400
在neo4j中可以吗?

My neo4j graph shows like below..
300 is connected to 100 and 100 is connected to 201 and 400.
I want to find out the 2nd level of connectivity in neo4j. For example: the 2nd level of node for 300 should return me 201 and 400
Is it possible in neo4j?

当我使用以下密码查询时:

when I use below cypher query:

MATCH(n)-[:CALLED * 2]-(结果)WHERE n.name ='300'返回结果
它应该只给我201和400,但它会像下面这样返回

MATCH (n)-[:CALLED*2]-(result) WHERE n.name = '300' RETURN result
It should give me only 201 and 400 ,but it return like below

推荐答案

在Neo4j中,这非常容易.如果您使用的是Cypher,则可能类似于:

This is very easy in Neo4j. If you're using Cypher it might be something like:

MATCH (n)-[:CALLED]-()-[:CALLED]-(result)
WHERE n.id = 300
RETURN result

我在这里假设id属性是用来保存标识号的,但是显然您可以更改它.

I'm assuming here that the id property is what is holding the identifying numbers, but obviously you can change that.

您甚至可以执行以下可变长度的路径:

You can even do variable length paths like this:

MATCH (n)-[:CALLED*2]-(result)
WHERE n.id = 300
RETURN result

尽管如此,部分问题在于这将返回节点#200.一个适合您寻找结果的查询是:

Part of the problem here, though, is that this will return node #200. One query that would fit the result your looking for is:

MATCH (n)-[:CALLED]->()<-[:CALLED]-(result)
WHERE n.id = 300
RETURN result

这仅在中间节点具有指向它的关系的地方匹配.

This matches only where the middle node has the relationships pointing to it.

这篇关于如何在neo4j中找到第二级连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆