cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Distinct full paths for a given node

Hi everyone,
For the following graph :
2X_f_f5b0d1595d480a08bbd7af3335679c42cd57512c.png

I would like to get all the distinct oriented paths for a given node.
For example, starting from x6, I would have 3 distinct paths :

  • x6 -> x3 -> x2 -> x1

  • x6 -> x3 -> x2 -> x4

  • x6 -> x3 -> x2 -> x5

I have tried this query: MATCH path = ({name:'x6'})-[*]->(n) RETURN path

And I obtained these results:

I think I just have to add clauses in my query, but I can't figure out which ones.

Thanks for your help.

4 REPLIES 4

What does this mean?

In your sample output, why wouldn't you also want to see x6 -> x3, x6 -> x3 -> x2, and other "intermediate" paths?

Yes I'm also interested by the "intermediate" paths but is it not possible to simplify by defining that they are included in the next 3 paths ?

  • x6 -> x3 -> x2 -> x1
  • x6 -> x3 -> x2 -> x4
  • x6 -> x3 -> x2 -> x5

I would like to "limit" the research of paths like this:

  • First node of the path -> a given node (x6 for example)
  • End node of the path -> leaf node (like x1 ?) OR a node before the given node (x4 and x5 for x6)

Have a look at this -- this might be what you mean / need, but I'm not sure

This would get you all of the paths, as short as possible, from your starting point to everything else, without replications I think.

Thanks David !
I also think about Shortest Path and Single Source Shortest Path algorithm because I will put cost on my relationship.

I found this code in neo4j documentation :
https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/single-source-shortest-path/