Neo4j 使用当前属性值的正则表达式重命名属性 [英] Neo4j rename property using regex of current property value

查看:27
本文介绍了Neo4j 使用当前属性值的正则表达式重命名属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的研究(大量谷歌搜索)来看,我看不出这是可能的,但我认为仍然值得一问.我有大量节点,例如:

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"})

其中 1234 可以是任何非负整数.

where 1234 can be any non-negative integer.

为了更新数据库以使用新的 API,我想重命名集合中的每一个,以便结果如下所示:

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"})

所以,我需要将 Org_ 与当前属性的 [0-9]+ 正则表达式匹配混搭.

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

真的,我什至不知道从哪里开始.我在文档中看到的只是正则表达式可以用作 WHERE 子句(WHERE n.property =~ {regex})中的谓词.有没有办法只使用 Cypher,因为我没有使用 Java 库?

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?

推荐答案

假设组织"和整数之间总是有一个空格,你可以很容易地使用字符串函数来暴力破解.

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

哪个返回

o.name
Org_1234
Org_5678

这篇关于Neo4j 使用当前属性值的正则表达式重命名属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆