Tuesday, June 28, 2022

[FIXED] How to create relationships in according to date order in Neo4j

Issue

I have many nodes and zero relationships. How can I create relationships that join the same person following date order? (the picture represents the situation I would like to obtain) See Image


Solution

If you have apoc, this is would be my approach.

MATCH (p:Person)
WITH p order by p.date
WITH p.name as personName, collect(p) as personList
WITH apoc.coll.pairsMin(personList) as pairs
UNWIND pairs as pair
WITH pair[0] as p0, pair[1] as p1
MERGE (p0)-[:SAME_PERSON]->(p1)


Answered By - Nathan Smith
Answer Checked By - Mildred Charles (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.