cancel
Showing results for 
Search instead for 
Did you mean: 

How do you return only one cycle?

depire
Node Clone

Dear all,

I look for the cypher code enable to return only one path.

I assume that I have, A->B1->C1->D1->B1 and A->B2->C2->D2->B2.
I would to retrieve the components of these 2 cycles.

I try the following code but I retrieve 6 cycles
MATCH path=(l:LEU)-[:REL*2..]->(l)
WHERE all(r in relationships(path))
RETURN relationships(path) as rel

I get
path1 : B1->C1->D1
path2 : C1->D1->B1
path3 : D1->B1->C1
path4 : B2->C2->D2
path5 : C2->D2->B2
path6 : D2->B2->C2

How can I update the code to retrieve only path1 and path4 following an order based on id of node ?

Regards,
Alexandre

1 REPLY 1

ameyasoft
Graph Maven
Try this:

MATCH (c:B1) 
CALL apoc.path.subgraphAll(c, {maxLevel: 2}) 
YIELD nodes, relationships
RETURN nodes, relationships

MATCH (c:B2)
CALL apoc.path.subgraphAll(c, {maxLevel: 2}) 
YIELD nodes, relationships
RETURN nodes, relationships
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.