返回与其他Neo4j相关的节点(Return Nodes related with a relatiohip to other Neo4j)

编程入门 行业动态 更新时间:2024-10-24 20:22:45
返回与其他Neo4j相关的节点(Return Nodes related with a relatiohip to other Neo4j)

我刚刚开始使用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 n

That 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 n

That 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,p

and 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 result

so check your data anyway :)

更多推荐

本文发布于:2023-07-26 00:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268323.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   与其他   Neo4j   Return   related

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!