我刚刚开始使用Neo4j,在创建整个图形之后,我试图通过关联来获得与另一个节点相关的所有节点。
Match (n)-[Friendship_with]->({Name:"Gabriel"}) return n这应该给我的节点是加布里埃尔的朋友,我做错了什么? 我也用过这个:
Match n-[r:Friendship_with]->n1 where n1.Name="Gabriel" return n这给了我一些节点,但其中一些与Gabriel没有直接关系(例如,Maria是Gabriel的朋友,当我写这篇文章时她出现了,但是作为Maria的朋友并且不是来自Gabriel的Alex也出现了)
i have just started using Neo4j, and after creating the whole graph i'm trying to get all the nodes related to another one by a relatioship.
Match (n)-[Friendship_with]->({Name:"Gabriel"}) return nThat should give me the nodes that are friend of Gabriel, what i'm doing wrong? I have used too this:
Match n-[r:Friendship_with]->n1 where n1.Name="Gabriel" return nThat give me some nodes, but some of then aren't directly related to Gabriel (for example, Maria is friend of Gabriel, she appears when i write that, but Alex who is friend of Maria and not from Gabriel, appear too)
最满意答案
这很奇怪。 您的查询是正确的。
我建议检查你的数据。 你确定亚历克斯和加布里埃尔之间没有任何直接联系吗?
您可以将您的图形可视化,并查看neo4j浏览器中正在发生的事情。 只需输入更多信息的查询,例如:
MATCH (n)-[f:Friendship_with]->(p {Name:"Gabriel"}) return n,f,p并使用图表视图检查您的数据。
编辑:
正如迈克尔指出的那样,您的第一个查询在指定的关系标签“Friendship_with”前面缺少一个冒号。 所以neo4j认为它是你的关系的一个(相当长的)变量名,就像'n'或'n1'一样。 因此,它将检索与Gabriel相关的任何内容,而无需通过关系标签进行过滤。
它没有解释为什么你:
使用第一个和第二个查询获得相同的结果 结果得到二度关系所以检查你的数据:)
This is weird. Your query is correct.
I would suggest to check your data. Are you sure there isn't any direct connection between Alex and Gabriel ?
You could visualize your graph and see what is happening exactly in the neo4j browser. Just type a query with a bit more info like:
MATCH (n)-[f:Friendship_with]->(p {Name:"Gabriel"}) return n,f,pand use the graph view to inspect your data.
EDIT:
As Pointed out by Michael, your first query is missing a colon in front of the specified relationship label "Friendship_with". So neo4j thinks it is a (rather long) variable name for your relationships, just as 'n' or 'n1'. It will thus retrieve anything that is connected to Gabriel without filtering by relationship label.
It doesn't explain though why you:
get the same results with the first and second query get a 2nd degree relation as a resultso check your data anyway :)
更多推荐
发布评论