How to return only end / leaf nodes in a cypher Neo4j request?

I have a structure like this:

user - [: talking] β†’ topic - [: category_in] β†’ topic [: categorized_in] β†’ topic ... etc.

Starting with the user, how do I get the most distant topics that they talk about. This is mainly represented by the top-level categories of which they speak. This is the only way I know this, and it returns all nodes along the path, not just the nodes of the sheet.

START user=node(1) MATCH user-[:talking]->x<-[:categorized_in*0..]-y RETURN distinct y.uuid 

This is my last attempt. This seems to work, although I don't know if this is suitable for this?

 START user=node(1) MATCH user-[:talking]->x<-[:categorized_in*0..]-y<-[?:pull]-z WHERE z is null RETURN distinct y.uuid 
+4
source share
2 answers

So here's how to do it for someone interested:

 START user=node(1) MATCH user-[:talking]->x<-[:categorized_in*0..]-y<-[?:categorized_in]-z WHERE z is null RETURN distinct y.uuid 
+2
source

Now you can filter the patterns in WHERE .

So, if you have a newer version of Neo4j, I think the request will look like

 START user=node(1) MATCH user-[:talking]->x<-[:categorized_in*0..]-y WHERE NOT(y<-[:categorized_in]-()) RETURN DISTINCT y.uuid 
+1
source

All Articles