Neo4j rename property using regex of current prope

2019-05-30 15:26发布

From my research (lots of Googling), I can not see that this is possible, but it is still worth asking I think. I have a large collection of nodes like:

(org:Organization {name: "Organization 1234"})

where 1234 can be any non-negative integer.

In order to update the DB to work with a new API, I am wanting to rename each of these in the collection so that the result would look something like:

(org:Organization {name: "Org_1234"})

So, I need to mashup Org_ with the [0-9]+ regex match on the current property.

Truly, I am at a loss on where to even start. All I see in the documentation is that regex can be used as a predicate in the WHERE clause (WHERE n.property =~ {regex}). Is there a way using just Cypher as I am not using a Java library?

标签: neo4j cypher
1条回答
相关推荐>>
2楼-- · 2019-05-30 16:06

Assuming there is always a single space between "Organization" and the integer, you can brute force this pretty easily with just string functions.

CREATE (:Organization {name:'Organization 1234'}), 
       (:Organization {name:'Organization 5678'})

MATCH (o:Organization)
WITH o, SPLIT(o.name, " ")[1] AS id
SET o.name = "Org_" + id
RETURN o.name

Which returns

o.name
Org_1234
Org_5678
查看更多
登录 后发表回答