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.

Cypher queries cannot produce the recursive query in tabular data to determine source and target

I have data that is stored in recursion using another object as below

(s:Source)-[r:Link]->(s1:Source)-[r:Link]->(s2:Source)

Though there can be some intermediate object(s) as well and the depth is not fixed. Can be one or 5 or 10 as well.

(s:Source)-[r:Link]->(f1:Feature)-[r:Link]->(s2:Source)

(s:Source)-[r:Link]->(f1:Feature)-[r:Link]->(f2:Feature)-[r:Link]->(s1:Source)

Another scenario is a Source can be linked to multiple Source/Feature and the they will be further linked in same way.

(s:Source)-[r:Link]->(f1:Feature)
(s:Source)-[r:Link]->(f2:Feature)
(s:Source)-[r:Link]->(f3:Feature)

(f1:Feature)-[r:Link]->(s1:Source)
(f2:Feature)-[r:Link]->(s2:Source)
(f3:Feature)-[r:Link]->(s3:Source)

I am using below query to get the data

MATCH(s:Source)-[r:Target-Feature *]->(n:Source)
return s.Name, n.Name;

Though I am able to get the data correctly, I am not able to display that dynamically in a tabular format which clearly shows the Sources at each hop(excluding intermediate Feature objects) including handling the multi to multi linking.

1 REPLY 1

Hi @rabindra.srivastava, welcome to the community!

You will probably find the nodes() and relationships() Cypher functions helpful.

You will probably do something like get your path, i.e.

MATCH path =(s:Source)-[r:Target-Feature *]->(n:Source)

and then, you will do something like nodes() to pull out the nodes, e.g.

RETURN nodes(p)

You can find the documentation to nodes() here. Have bit of a play with this, and hopefully you'll get what you're after.

Cheers,

Lju