Change node label in neo4j

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Change node label in neo4j



I have created a node with a wrong label.
Is there any way to change node label or relationship type without re-creating it?
I have tried something like



MATCH n WHERE Id(n)=14 SET n.Labels = 'Person'



but it is fault...




4 Answers
4



You can change the nodes associated with a label but you can't change the type of a relationship. Conceptually, if you take your chicken out of one coop and put it in another you haven't altered the substance of the chicken. But by the time you take the chicken out of the oven and put it in your mouth, it's not a chicken anymore (except equivocally). You can decide to call your cat Whiskers instead of Charlie, but if you decide you want an anaconda for a pet instead of a cat, it doesn't help to give the cat a new name. Similarly, a node can be a member of different labels and remain the same node, but a relationship's type is constitutive. So: you can add and remove labels as you please, but if you want a different relationship type then what you want is really a different relationship. This is also why a relationship has exactly one type, but a node can have many labels.



Labels are arbitrary sets or bags of nodes. The grammar for changing bags has already been given, but for completeness:


MATCH (n)
WHERE ID(n) = 14
REMOVE n:Whiskers
SET n:Charlie

MATCH (petless_and_unhappy)-[whiskers:CAT]->(petful_and_unhappy)
DELETE whiskers
CREATE (petless_and_unhappy-[sir_hiss:ANACONDA]->(peftul_and_happy)





If there's an analogy intended for the chicken/cat/anaconda example, I'm not following it. All those things are nouns, perhaps you want to use verbs for relationships or something?
– Ken Williams
Dec 26 '14 at 19:47


MATCH (n:OLD_LABEL {id:14})
REMOVE n:OLD_LABEL
SET n:NEW_LABEL



Guess this query explains itself.





I don't understand why delete relatioship. And in my case it goes little different with id: MATCH (n:Node) WHERE Id(n) = 14 REMOVE n:Node SET n:Person
– tsdaemon
Mar 21 '14 at 5:57




MATCH (n:Node) WHERE Id(n) = 14 REMOVE n:Node SET n:Person





{id:14} is not right, use ID(n) = 14 instead. (neo4j 3)
– G. Ghez
Feb 8 '17 at 14:44


{id:14}


ID(n) = 14



This should work for changing labels on multiple nodes simultaneously:


MATCH (n:OLD_LABEL)
WHERE ID(n) IN [7, 8]
REMOVE n:OLD_LABEL
SET n:NEW_LABEL



Match (n:person{name:'John Jjones'}) Set n.name = 'John Jones'






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results