Get nodes that do not have a specific relationship (cypher / neo4j)

I have the following two types of node:

c:City {name: 'blah'} s:Course {title: 'whatever', city: 'New York'} 

Want to create this:

 (s)-[:offered_in]->(c) 

I try to get all courses that are NOT tied to cities and do not create a relationship with the city (a city is created if it does not exist). However, the problem is that my data set is about 5 million nodes, and any request I make is disconnected (if I don't do it in 10k steps).

... does anyone have any advice?

EDIT:

Here is the request for the tasks that I am starting now (it needs to be done in 10 thousand pieces (out of millions), because it takes several minutes as it is. Creates a city if it does not exist):

 match (j:Job) where not has(j.merged) and has(j.city) WITH j LIMIT 10000 MERGE (c:City {name: j.city}) WITH j, c MERGE (j)-[:in]->(c) SET j.merged = 1 return count(j) 

(I don’t know yet how to filter out those that are already mapped correctly, so we’ll try to do this by marking it with a custom “merged” attribute that already has an index)

+6
source share
1 answer

500,000 is a fair number of nodes, and on your other question that you suggested, 90% were without the relationships you want to create here, so this will take a little time. Without additional knowledge about your system (specification, neo configuration, programming environment), and when you run it (according to old data or by insertion), this is simply the best guess for a finer solution:

 MATCH (j:Job) WHERE NOT (j)-[:IN]->() AND HAS(j.city) MERGE (c:City {name: j.city}) MERGE (j)-[:IN]->(c) return count(j) 

Obviously, you can add your restrictions as needed.

+2
source

Source: https://habr.com/ru/post/974842/


All Articles