Neo4j - 批量编辑节点属性 - 即批量编辑所有键(n)
Neo4j - Mass edit node properties - i.e. mass edit all keys(n)
我正在尝试执行一些数据清理,我正在寻找一种方法来批量编辑一组节点上的所有 属性 键。就我而言,我想将所有键 (n) 设为大写,并用“_”替换空格,而不管列名如何。
以下设置会执行此操作,但假设您知道密钥的具体名称。
MATCH (c:Category)
UNWIND keys = collKeys
SET c.COMPANY = c.Company
REMOVE c.Company
return c limit 1000
下面构建了一个当前键列表,然后是我想要的标签。我只是不确定如何正确调整 SET。
我正在尝试找到一种方法来对我所有的键进行大写 (c)
//SET c.REPLACE(toUPPER(c.Company)," ", "") = REPLACE(toUPPER(c.Company) , ", "")
MATCH (c:Category)
UNWIND keys(c) as collKeys
WITH DISTINCT collKeys
WITH collKeys, REPLACE(toUPPER(collKeys)," ", "_") as collUPPERKeys
WHERE collKeys <> 'source'
SET c.collUPPERKeys = REPLACE(toUPPER(c.collKeys)," ", "_") //<-- this is where I'm struggling as c.collUPPERKeys doesn't make sense
REMOVE c.collKeys
return c
我知道最佳做法是在导入时执行此操作,但我目前还无法访问该代码,但我打算在数据加载时执行此操作。
非常感谢
编辑 - 是否有可以执行此操作的 apoc 函数?
您将需要 APOC 来创建动态属性:请查看以下内容 post:https://dzone.com/articles/neo4j-dynamically-add-propertyset-dynamic-property
CALL apoc.create.setProperty(c, collUPPERKeys, replace(...))
与删除动态属性类似,您还需要 APOC。
CALL apoc.create.removeProperties(c, collKeys)
YIELD 节点
如果我们把它们放在一起:
MATCH (c:Category)
WITH c
UNWIND keys(c) as collKeys
WITH collKeys,c
WITH collKeys, REPLACE(toUPPER(collKeys)," ", "_") as collUPPERKeys,c
WHERE collKeys <> 'source'
// set dynamic properties
CALL apoc.create.setProperty(c, collUPPERKeys, replace(toUPPER(c.collKeys)," ", "_")) YIELD node as foo
// remove dynamic properties
CALL apoc.create.removeProperties(c, [collKeys]) YIELD node
return c
我正在尝试执行一些数据清理,我正在寻找一种方法来批量编辑一组节点上的所有 属性 键。就我而言,我想将所有键 (n) 设为大写,并用“_”替换空格,而不管列名如何。
以下设置会执行此操作,但假设您知道密钥的具体名称。
MATCH (c:Category)
UNWIND keys = collKeys
SET c.COMPANY = c.Company
REMOVE c.Company
return c limit 1000
下面构建了一个当前键列表,然后是我想要的标签。我只是不确定如何正确调整 SET。 我正在尝试找到一种方法来对我所有的键进行大写 (c)
//SET c.REPLACE(toUPPER(c.Company)," ", "") = REPLACE(toUPPER(c.Company) , ", "")
MATCH (c:Category)
UNWIND keys(c) as collKeys
WITH DISTINCT collKeys
WITH collKeys, REPLACE(toUPPER(collKeys)," ", "_") as collUPPERKeys
WHERE collKeys <> 'source'
SET c.collUPPERKeys = REPLACE(toUPPER(c.collKeys)," ", "_") //<-- this is where I'm struggling as c.collUPPERKeys doesn't make sense
REMOVE c.collKeys
return c
我知道最佳做法是在导入时执行此操作,但我目前还无法访问该代码,但我打算在数据加载时执行此操作。
非常感谢
编辑 - 是否有可以执行此操作的 apoc 函数?
您将需要 APOC 来创建动态属性:请查看以下内容 post:https://dzone.com/articles/neo4j-dynamically-add-propertyset-dynamic-property
CALL apoc.create.setProperty(c, collUPPERKeys, replace(...))
与删除动态属性类似,您还需要 APOC。
CALL apoc.create.removeProperties(c, collKeys)
YIELD 节点
如果我们把它们放在一起:
MATCH (c:Category)
WITH c
UNWIND keys(c) as collKeys
WITH collKeys,c
WITH collKeys, REPLACE(toUPPER(collKeys)," ", "_") as collUPPERKeys,c
WHERE collKeys <> 'source'
// set dynamic properties
CALL apoc.create.setProperty(c, collUPPERKeys, replace(toUPPER(c.collKeys)," ", "_")) YIELD node as foo
// remove dynamic properties
CALL apoc.create.removeProperties(c, [collKeys]) YIELD node
return c