cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to reverse relations on 10 million objects

HI, I need to reverse the relation on 10 million objects what the script should look like using apoc.periodic.iterate

<MATCH (n:Reservation)-[rel:has]->(p:Person) CALL apoc.refactor.invert(rel) yield input, output RETURN input, output/>

Important! I use Neo4j server version: 3.6

3X_0_3_03e4bc01d4ef377028439c18b438452673170b32.png
3X_4_7_479a36d781ec42e310442ed8d78f2a20517eb656.png

1 ACCEPTED SOLUTION

Thanks @Bennu

We used below code:


CALL apoc.periodic.iterate(
   "MATCH (n:Reservation)-[rel:has]->(p:Person) return rel",
   "UNWIND $_batch AS item CALL apoc.refactor.invert(item.rel) YIELD input, output RETURN input, output",
   {batchMode: "BATCH_SINGLE", batchSize: 1000}
)
YIELD batches, operations
RETURN batches, operations AS total

View solution in original post

2 REPLIES 2

Bennu
Graph Fellow

Hi @Slawomir_Jaros !

I do like periodic commit a bit more.

CALL apoc.periodic.commit(
  "MATCH (n:Reservation)-[rel:has]->(p:Person)
   WITH rel limit $limit
   CALL apoc.refactor.invert(rel) yield input, output
   RETURN count(*)",
  {limit:10000});

Tuning on limit according to the max heap on your server.

Lemme know how it goes.

Bennu

Thanks @Bennu

We used below code:


CALL apoc.periodic.iterate(
   "MATCH (n:Reservation)-[rel:has]->(p:Person) return rel",
   "UNWIND $_batch AS item CALL apoc.refactor.invert(item.rel) YIELD input, output RETURN input, output",
   {batchMode: "BATCH_SINGLE", batchSize: 1000}
)
YIELD batches, operations
RETURN batches, operations AS total