All paths with 2 relations by nodes


This is my graph :
Capture d’écran, le 2020-01-28 à 20.27.11

I want to do a request that return all the loops in the graph (all the paths), where all the node have two relations, one that leave and one that arrive (one :NEED and one :OFFEREDBY).

How can I restrict (write) the request ? I didn't manage to do it with [:RELTYPE'*1] or [:RELTYPE'*1..1]

In other words, this is the answer desired :

thank you!


Can you elaborate on this? What constitutes a valid result vs an invalid result? Some examples showing what you want, and what you don't want may help.

I can put more pictures,

But I dont want all the graph in the answer, I want all the different closed loops, all the different paths.

I hope to be more clear :confused:

In a previous edit I saw you had a query already that generated the patterns, it looks like you want to refine that query?

Will something like this work for you?


With some acceptable upper bound of course. This traverses all outgoing :NEED and :OFFEREDBY relationships, and the results back will be those that loop back to the start.

Unfortunately, this give me all the graph again :

Capture d’écran, le 2020-01-28 à 21.10.58

I really would like two distinct paths that show the loops that the graph have (only with 2 relations by nodes, one arriving, one leaving).

A query that give me that :

Oh, so you want the graph to show the same node per pattern where it's matched?

That can't currently be done by the Neo4j visualizer. Nodes are distinct, it can't display the same node multiple times in different contexts. The graphical results are a union of the query results. You would need to execute separate queries (maybe using SKIP and LIMIT) to visualize each graph separately.

Oh, I see..
It gonna be less easy than expected..

Thank you so much for your help !