Reputation: 876
i have this sample graph:
http://console.neo4j.org/?id=mginka
and i'm trying to find a Cypher code,that will connect all the hits nodes of each session by the date_time field with [NEXT] relation – hits from different sessions shouldn't be connected..
thanks, Lior
Upvotes: 1
Views: 32
Reputation: 20185
Based on your console graph, this query do the trick :
MATCH (session:Session)
MATCH (session)<-[:IN_SESSION]-(hit)
WITH session, hit
ORDER BY hit.date_time ASC
WITH session, collect(hit) AS hits
UNWIND range(1, size(hits)-1) AS hitKey
MATCH (prev) WHERE id(prev) = id(hits[hitKey-1])
MATCH (current) WHERE id(current) = id(hits[hitKey])
MERGE (prev)-[:NEXT]->(current)
Upvotes: 2