cancel
Showing results for 
Search instead for 
Did you mean: 

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

aashish_k_shah
Node Link

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

1 ACCEPTED SOLUTION

12kunal34
Graph Fellow

Try

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

hope this works in your case

View solution in original post

4 REPLIES 4

12kunal34
Graph Fellow

Try

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

hope this works in your case

Thanks Kunal .. that worked perfectly fine !!

david_allen
Neo4j
Neo4j

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 David for your response.