I have Nodes which contain the id and the attribut employee. These Nodes are named Employee.
And Nodes which contains the dep attribute. These are named Department
How can I create for all of them a relationship between the employee and dep.
This is my solution but it is really slow. It need to be quite fast because the json document contains thousand of json objects.
CALL apoc.periodic.iterate(
"CALL apoc.load.json('sampled.json') YIELD value
UNWIND value.employees as employee RETURN employee",
"MATCH (e:employee {employee: employee.employee})
MATCH (d:Department {dep:employee.dep})
MERGE(e)-[r:workAt]->(d)",
{batchSize:8000,parallel:false}
)
this effectively says find me a node with label :employee and which has a property named employee and the value for this property is what is represented by employee.employee.
Now if you have an index on :employee(employee) then the query will be really fast as it will use the index to find the record.
If you do not have a index on :employee(employee) then to find said node it will need to iterate over each and every :employee node, whether than be 100 nodes of 100k nodes