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.

Adding a prefix or suffix to existing relation property

Is there a way to update the existing relationship property with a prefix without losing the existing property value in there.
in the following example, I have connected multiple nodes by level 1, 2, 3. I would like to update the property level with prefix "Journey" for the following graph using cypher.
I have tried using "set" but its overriding the existing level value.

1 ACCEPTED SOLUTION

Hi,

if you want to change the value of the property you can do it by concatenating your prefix with the existing value, e.g.

MATCH (a)-[r]->(b)
SET r.level= "Journey " + r.level

This will change the values from "1", "2", "3",... to "Journey 1", "Journey 2", "Journey 3"...

Or if you want to change the name of the property you can do

MATCH (a)-[r]->(b)
SET r.JourneyLevel = r.level
REMOVE r.level

This will create a new property with the old property's value and remove the old property.

Regards,
Elena

View solution in original post

4 REPLIES 4

intouch_vivek
Graph Steward

Hi,

Welcome to the community.
Is that you are trying to update the relationship property name from level to Journey Level?
Please let me know the query you are trying to run which is not giving you the expected result and what is your expected result.

Regards
Vivek

Thank you.
i was using
MATCH (a)-[r]->(b)
SET r.level= "Journey"
but the following query provided by elen worked for me.

Hi,

if you want to change the value of the property you can do it by concatenating your prefix with the existing value, e.g.

MATCH (a)-[r]->(b)
SET r.level= "Journey " + r.level

This will change the values from "1", "2", "3",... to "Journey 1", "Journey 2", "Journey 3"...

Or if you want to change the name of the property you can do

MATCH (a)-[r]->(b)
SET r.JourneyLevel = r.level
REMOVE r.level

This will create a new property with the old property's value and remove the old property.

Regards,
Elena

Thank you. the first one worked.