how to find 2nd level of connections in neo4j?

廉价感情. 提交于 2019-12-08 20:28:34

问题


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]-(result) WHERE n.name = '300' RETURN result
It should give me only 201 and 400 ,but it return like below


回答1:


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

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

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.



来源:https://stackoverflow.com/questions/29764435/how-to-find-2nd-level-of-connections-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!