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.

Change Relationships name

Hello Everyone

I just want to know how I can change the name of relationships in neo4j. I have many relationships that have label "IS_CONNECTED_TO". Right now I want to substitute them all with "KNOWS". Does anybody know how I can do it?

Thanks

6 REPLIES 6

You cannot rename a relationship, but you can create a new one and delete the old one.

So you could do something like this:

MATCH (n)-[rel:IS_CONNECTED_TO]->(m)
MERGE (n)-[:KNOWS]->(m)
DELETE rel

If the relationship has properties, then you would need to add them when you merge.

Elaine

Thanks Elaine, it worked

what if in case of condition in where clause in relation ship

ameyasoft
Graph Maven

Use APOC Refactoring:

MATCH (n)-[rel:IS_CONNECTED_TO]->(m) WITH rel
CALL apoc.refactor.setType(rel, 'KNOWS') YIELD input, output RETURN *

Result:
MATCH (n)-[:KNOWS]->(m)

Hi Ameyasoft
I am not very familiar yet with APOC. but your advice encouraged me to start and learn APOC. Thank you very mucj

Hey Ameya, This helped me a lot. Thank you.
Could kindly share how to change the Node Label Name (Constraint) using APOC ?