[英]How to return only the end/leaf nodes in a Neo4j cypher query?
I have a structure like so: 我有这样的结构:
user-[:talking]->topic-[:categorized_in]->topic[:categorized_in]->topic... etc user - [:talking] - > topic - [:categorized_in] - > topic [:categorized_in] - > topic ... etc
Starting at a user, how would I get the furthest away topics they're talking about. 从用户开始,我将如何获得他们所谈论的最远的话题。 Basically this represents the top level categories they are talking about.
基本上这代表了他们所谈论的顶级类别。 This is the only way I know to go about doing this, and it returns all of the nodes along the way, not just the leaf nodes.
这是我知道的唯一方法,它会返回所有节点,而不仅仅是叶节点。
START user=node(1)
MATCH user-[:talking]->x<-[:categorized_in*0..]-y
RETURN distinct y.uuid
This is my latest attempt. 这是我最近的尝试。 It seems to work, though I don't know if this is the best way to go about it?:
它似乎有效,但我不知道这是否是最好的方法呢?:
START user=node(1)
MATCH user-[:talking]->x<-[:categorized_in*0..]-y<-[?:pull]-z
WHERE z is null
RETURN distinct y.uuid
So this is how to do it for anybody interested: 所以这是为任何感兴趣的人做的:
START user=node(1)
MATCH user-[:talking]->x<-[:categorized_in*0..]-y<-[?:categorized_in]-z
WHERE z is null
RETURN distinct y.uuid
You can now filter against patterns in the WHERE . 您现在可以过滤WHERE中的模式 。
So if you have a newer version of Neo4j, I think the query would look like 所以,如果您有更新版本的Neo4j,我认为查询看起来像
START user=node(1)
MATCH user-[:talking]->x<-[:categorized_in*0..]-y
WHERE NOT(y<-[:categorized_in]-())
RETURN DISTINCT y.uuid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.