Cypher query not returning expected result for roots and leaves of a graph

I have created a graph of applications talking to each other. There are few roots nodes which do not have any incoming edges and few leaves who do now have any outgoing edges. Other nodes are part of branches via which application talk to each other.

I wrote a CYPHER query to identify the pattern of nodes which do not have any out going edges, meaning leaves of the graph. But no getting any result.

Have attached the screen shot of the graph and also the query for leaves. Please suggest what am I doing wrong.

Query for identifying leaves:
MATCH (x:App)-[r:TALKS_TO]->(y:App) WHERE not((x)-->()) return (x)
Result: (no changes, no records)

Thanks,
Ashish

Try

MATCH (n)
WHERE size((n)-->())=0
Return n

hope this works in your case

1 Like

I think you need to refine this. This query here expresses something that's impossible, so you always get nothing back. You said here that you want x nodes that have a TALKS_TO relationship outgoing to y, and you asked to filter that list to only x nodes with no outbound relationships. Which will always be an empty list, because it's a contradiction.

Maybe you want to change the not clause to be looking for relationships the other direction?

Thanks Kunal .. that worked perfectly fine !!

Thanks David for your response.