forked from mneedham/yelp-graph-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_apoc_iterate.cypher
67 lines (62 loc) · 2.41 KB
/
import_apoc_iterate.cypher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:///Users/markneedham/projects/yelp-graph-algorithms/dataset/business.json')
YIELD value
WITH value LIMIT 1000
RETURN value",
"MERGE (b:Business {id:value.business_id})
SET b += apoc.map.clean(value,
['attributes','hours','business_id','categories',
'address','postal_code'],
[])",
{iterateList: true, batchSize:500, parallel: true});
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:///Users/markneedham/projects/yelp-graph-algorithms/dataset/business.json')
YIELD value
WITH value LIMIT 1000
RETURN value",
"MATCH (b:Business{id:value.business_id})
WITH b,value.categories as categories
UNWIND categories as category
MERGE (c:Category {name:category})
MERGE (b)-[:IN_CATEGORY]->(c)",
{iterateList: true, batchSize:500});
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:///Users/markneedham/projects/yelp-graph-algorithms/dataset/user.json')
YIELD value
WITH value LIMIT 1000
RETURN value",
"MERGE (u:User {id:value.user_id})
SET u += apoc.map.clean(value, ['friends','user_id'], [])",
{iterateList: true, batchSize:500, parallel: true});
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:///Users/markneedham/projects/yelp-graph-algorithms/dataset/user.json')
YIELD value
WITH value LIMIT 1000
RETURN value",
"MATCH (u:User {id:value.user_id})
WITH u, value.friends as friends
UNWIND friends as friend
MERGE (u1:User {id:friend})
MERGE (u)-[:FRIENDS]-(u1)",
{iterateList: true, batchSize:500});
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:///Users/markneedham/projects/yelp-graph-algorithms/dataset/review.json')
YIELD value
WITH value LIMIT 50000
RETURN value",
"MERGE (b:Business {id:value.business_id})
MERGE (u:User {id:value.user_id})
MERGE (r:Review {id:value.review_id})",
{iterateList: true, batchSize:500, parallel: true});
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:///Users/markneedham/projects/yelp-graph-algorithms/dataset/review.json')
YIELD value
WITH value LIMIT 1000
RETURN value",
"MATCH (b:Business {id:value.business_id})
MATCH (u:User {id:value.user_id})
MATCH (r:Review {id:value.review_id})
MERGE (u)-[:WROTE]->(r)
MERGE (r)-[:REVIEWS]->(b)
SET r += apoc.map.clean(value, ['business_id','user_id','review_id'], []);",
{iterateList: true, batchSize:500});