从 Neo4j 中的大量节点中删除属性
remove attribute from very large number of nodes in neo4j
我有 Neo4j 数据库,其中包含数百万个 person 类型的节点,我想删除所有 person 节点的特定属性。我试图通过匹配查询来实现它,但它正在扫描所有节点。
这是我试过的查询。
MATCH (p:Person)
REMOVE p.fatherName
是否有其他快速替代此查询的方法,
无法通过 Cypher 提高该查询的性能。
你可以尽量避免没有 fatherName 的节点 属性
MATCH (p:Person)
WHERE HAS (p.fatherName)
REMOVE p.fatherName
此外,添加 LIMIT 和 运行 多次查询也有帮助
MATCH (p:Person)
WHERE HAS (p.fatherName)
WITH p LIMIT 100000
REMOVE p.fatherName
我建议你写 Unmanaged Extension 删除 属性。
例如
Label nodeLabel = DynamicLabel.label("Person");
String propertyName = "fatherName";
try(Transaction tx = database.beginTx()) {
final ResourceIterator<Node> people = database.findNodes(nodeLabel);
for (Node person : IteratorUtil.asCollection(people)) {
if (person.hasProperty(propertyName)) {
person.removeProperty(propertyName);
}
}
tx.success();
}
我有 Neo4j 数据库,其中包含数百万个 person 类型的节点,我想删除所有 person 节点的特定属性。我试图通过匹配查询来实现它,但它正在扫描所有节点。
这是我试过的查询。
MATCH (p:Person)
REMOVE p.fatherName
是否有其他快速替代此查询的方法,
无法通过 Cypher 提高该查询的性能。
你可以尽量避免没有 fatherName 的节点 属性
MATCH (p:Person)
WHERE HAS (p.fatherName)
REMOVE p.fatherName
此外,添加 LIMIT 和 运行 多次查询也有帮助
MATCH (p:Person)
WHERE HAS (p.fatherName)
WITH p LIMIT 100000
REMOVE p.fatherName
我建议你写 Unmanaged Extension 删除 属性。
例如
Label nodeLabel = DynamicLabel.label("Person");
String propertyName = "fatherName";
try(Transaction tx = database.beginTx()) {
final ResourceIterator<Node> people = database.findNodes(nodeLabel);
for (Node person : IteratorUtil.asCollection(people)) {
if (person.hasProperty(propertyName)) {
person.removeProperty(propertyName);
}
}
tx.success();
}