简体   繁体   English

在Cypher中查找具有两个不同关系的节点

[英]Find node having two distinct relationship in Cypher

I am a newbie in Cypher. 我是Cypher的新手。 I am trying to find a query which will returns nodes having more than one relationship to other nodes. 我试图找到一个查询,该查询将返回与其他节点具有多个关系的节点。 Please refer to http://neo4j.com/docs/snapshot/images/cypher-match-graph.svg for the structure. 有关结构,请参阅http://neo4j.com/docs/snapshot/images/cypher-match-graph.svg I am trying to find the person who has acted in some movie(s) and also a father. 我试图找到曾在某些电影中饰演过的人以及父亲。 When I am running below query, it is giving me 0 records: 当我在查询下运行时,它给了我0条记录:

START n=node(*)
MATCH (n)-[r]->()
WHERE type(r)="ACTED_IN" AND type(r)="FATHER"
RETURN n,count(n); 

However, when I am running below query, it does return data but that I think is not what I wanted: 但是,当我在查询下运行时,它确实返回数据,但我认为不是我想要的:

START n=node(*)
MATCH (n)-[r]->()
WHERE type(r)="ACTED_IN" OR type(r)="FATHER"
RETURN n,count(n);

So basically, I need a query which will fetch only Charlie Sheen since he acted in Wall Street movie and also father of Martin Sheen 因此,基本上,我需要一个查询,该查询将仅提取自查理·辛(Charlie Sheen)以来,因为他曾在华尔街电影中饰演过父亲

I have tried to follow what others are saying in Cypher query to find nodes that have 3 relationships or How to retrieve the nodes with multiple relationships using cypher query or Cypher query to find nodes that have 3 relationships but not able to fathom the trick :( 我试图遵循其他人在Cypher查询中所说的来查找具有3个关系的节点,或者如何使用cypher查询Cypher查询来查找具有3个关系但不能理解技巧的节点 :(

Any help will be of much appreciation ! 任何帮助将不胜感激!

The right way to query this is: 查询此问题的正确方法是:

MATCH (p:Person)-[:ACTED_IN]->(), (p)-[:FATHER]->()
RETURN p

You're looking for a :Person node having and ACTED_IN relationship and (since p is used again) having a :FATHER relationship. 您正在寻找具有和ACTED_IN关系并且(由于再次使用了p )具有:FATHER关系的:Person节点。 I'm using anonymous nodes at the other end, since we're not interested in the endpoint - just the fact that it is connected is interesting. 我在另一端使用匿名节点,因为我们对端点不感兴趣-仅连接端点这一事实很有趣。

An alternative way to express that: 另一种表达方式:

MATCH ()<-[:FATHER]-(p:Person)-[:ACTED_IN]->()
RETURN p

Note that you shouldn't use START (unless querying manual indexes) any more. 请注意,您不应再使用START (除非查询手动索引)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM