I created a Needham time tree (http://www.markhneedham.com/blog/2014/04/19/neo4j-cypher-creating-a-time-tree-down-to-the-day/) going down to the hour. On each hour node I stored the epoch time
CREATE (h:Hour {hour: hour, day:day, month: month, year:year, time: apoc.date.parse(year +"-"+month+"-"+day+" "+hour+":00", "s", "yyyy-MM-dd hh:mm")})
Now I want to link events that happened within that hour to the hour node. I did this with the following query:
//Create one example event node
create (e:Event {time: apoc.date.parse("2017-11-17 13:15", "s", "yyyy-mm-dd HH:mm")})
with e
match (h:Hour) where h.time <= e.time and (h.time+3600) > e.time
merge (e)-[:IN_HOUR]->(h)
I indexed both the event time and hour time.
This works well for small groups of events but when I scale the events up to the hundreds of thousands range it goes VERY slowly. (On the order of a few hundred to 1000 relationships per hour)
How can I do this faster?
I tried both
match (e:Event) ...`
and using load CSV
to iterate over each event, match it to an existing event node and then create a relationship to the time tree.
`