Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-07-2022 02:02 AM
Hello,
I am using apoc.nodes.link to create links between nodes in chronological order. So far so good, but I want to use a group by or for each to create chains depending on an attribute of the node.
The query I use to generate the links for events of type A, B and C is:
match (e:myevents{Eventtype:'A' }) with e order by e.timestamp
WITH collect (e) as chain
CALL apoc.nodes.link(chain, 'NEXT_EVENTS',{avoidDuplicates: true}) RETURN chain;
match (e:myevents{Eventtype:'B' }) with e order by e.timestamp
WITH collect (e) as chain
CALL apoc.nodes.link(chain, 'NEXT_EVENTS',{avoidDuplicates: true}) RETURN chain;
match (e:myevents{Eventtype:'C' }) with e order by e.timestamp
WITH collect (e) as chain
CALL apoc.nodes.link(chain, 'NEXT_EVENTS',{avoidDuplicates: true}) RETURN chain;
Any suggestions on how I can make this dynamic so that the chains are generated for each of the eventtypes?
12-07-2022 10:01 PM
I am not sure this is what you meant, but I tried what I thought you meant.
with ['A','B','C'] as eventTypes
unwind eventTypes as eventType
match (e:myevents{Eventtype:eventType})
with eventType, e
order by e.timestamp
with eventType, collect (e) as chain
call apoc.nodes.link(chain,'NEXT_EVENTS',{avoidDuplicates: true})
return *
Before:
After:
All the sessions of the conference are now available online