@ Procedure ( mode = Mode . WRITE ) @ Description ( "apoc.refactor.rename.type(oldType, newType, [rels]) | rename all relationships with type 'oldType' to 'newType'. If 'rels' is provided renaming is applied to this set only" ) public Stream < BatchAndTotalResultWithInfo > type ( @ Name ( "oldType" ) String oldType , @ Name ( "newType" ) String newType , @ Name ( value = "rels" , defaultValue = "" ) List < Relationship > rels ) { String cypherIterate = rels != null && ! rels . isEmpty ( ) ? "UNWIND {rels} AS oldRel WITH oldRel WHERE type(oldRel)=\"" + oldType + "\" RETURN oldRel,startNode(oldRel) as a,endNode(oldRel) as b" : "MATCH (a)-[oldRel:`" + oldType + "`]->(b) RETURN oldRel,a,b" ; String cypherAction = "CREATE(a)-[newRel:`" + newType + "`]->(b)" + "SET newRel+=oldRel DELETE oldRel" ; Map < String , Object > parameters = MapUtil . map ( "batchSize" , 100000 , "parallel" , true , "iterateList" , true , "params" , MapUtil . map ( "rels" , rels ) ) ; return getResultOfBatchAndTotalWithInfo ( newPeriodic ( ) . iterate ( cypherIterate , cypherAction , parameters ) , db , null , oldType , null ) ; }
Rename the Relationship Type by creating a new one and deleting the old .