Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j:Cypher:如何按模式删除标签?_Neo4j_Cypher_Spring Data Neo4j - Fatal编程技术网

Neo4j:Cypher:如何按模式删除标签?

Neo4j:Cypher:如何按模式删除标签?,neo4j,cypher,spring-data-neo4j,Neo4j,Cypher,Spring Data Neo4j,我有一个Neo4j数据库,其中每个节点都有以下划线开头的标签 例如,(:User,\u User),(:Store,:\u Store)等 这些下划线标签是由Spring数据Neo4j生成的,现在我想去掉它们(call db.schema()将它们作为模式中的一个单独节点返回) 目标是只获取(:用户),(:存储) 有什么方法可以通过一些查询来做到这一点吗?如果从这些节点中删除以下划线开头的标签(例如,\u User),并将其替换为不带undescore的值,那么对db.schema()的调用将不

我有一个Neo4j数据库,其中每个节点都有以下划线开头的标签

例如,
(:User,\u User),(:Store,:\u Store)

这些下划线标签是由Spring数据Neo4j生成的,现在我想去掉它们(
call db.schema()
将它们作为模式中的一个单独节点返回)

目标是只获取
(:用户),(:存储)


有什么方法可以通过一些查询来做到这一点吗?

如果从这些节点中删除以下划线开头的标签(例如,
\u User
),并将其替换为不带undescore的值,那么对
db.schema()
的调用将不再返回这些值

你可以这样做

MATCH (n:_User)
SET n:User 
REMOVE n:_User
根据反馈更新答案。你可以用APOC做类似的事情

// get all labels that start with underscore
CALL db.labels()
YIELD label AS old_label
WHERE old_label STARTS WITH '_'
WITH old_label, substring(old_label, 1, length(old_label)) AS new_label

// match the nodes for one of the underscore labels
MATCH (n)
WHERE old_label IN labels(n)
WITH old_label, new_label, collect(n) AS relabel_nodes

// call removeLabels with the list of nodes and list od labels to remove
CALL apoc.create.removeLabels(relabel_nodes, [old_label])
YIELD node AS removed_label_node

// call addLabels with the new label to add
WITH removed_label_node, new_label
CALL apoc.create.addLabels(removed_label_node, [new_label])
YIELD node AS added_label_node
RETURN added_label_node

Dave,我有大约160个带下划线的独特标签,所以我希望通过一些查询一次性完成这项工作,而不是手动删除每个带下划线的标签。明白了。添加了一个更新,我想会让你开始。最后,我手动去了,因为我忘了提到我在Neo4j 2.3.5上,没有APOC。将此答案标记为正确,因为未提及版本,它将在将来帮助某人。谢谢