如何在 Neo4j 中根据日期顺序创建关系

How to create relationships in according to date order in Neo4j

我有很多节点和零个关系。如何创建按照日期顺序加入同一个人的关系? (图片代表我想获得的情况) See Image

如果你有 apoc,这就是我的方法。

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)