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.

How to find shortest path for all nodes starts from specific?

I need your help in neo4j project. I made two nodes Artist and Song. The relationship of these nodes is

(a:Artist)-[:SING]->(s:Song) I want to find all artists with shortest path lengths > 25 from artist ‘John Lennon’. The shortest paths will be calculated only on edges between artists and songs. Also, I want to return artist name, the length and the song titles for each path. I tried the bellow

MATCH (a:Artist { name: 'John Lennon' }), p = shortestPath((a)-[:SING*]-(s:Song))
WHERE ALL (r IN relationships(p) WHERE EXISTS (r.role)) AND length(p) > 25
RETURN a.name as artist ,length(p) as length, s.title

or 

MATCH (a:Artist)-[SING*]->(s:Song)
,(Lennon:Aartist),
p = shortestPath((Lennon)-[*]-()) 
WHERE  a.name='John Lennon' AND length(p) > 25
RETURN a.name as artist ,length(p) as length, s.title

But they didn't work.

Any idea what I did wrong?

3 REPLIES 3

Hi @marianapet55,

Looks like
Artist -> SINGS ( one of more) -> Songs
A Song -> SANG (by one or more) -> Artists

are you looking for the count of songs sung my an artist ???
or a how many artist sang a song ??

Hello,
Thank you for your response.

I want to find all artists with shortest path lengths > 25 from artist ‘John Lennon’.
Also the shortest paths will be calculated only on edges between artists and
songs. So i want to know all shortest path from john to others with lengths >25.

Can you share your schema ?