簡體   English   中英

從neo4j中的大量節點中刪除屬性

[英]remove attribute from very large number of nodes in neo4j

我有neo4j數據庫,其中包含數百萬個類型為person的節點,我想刪除所有person節點的特定屬性。 我試圖通過match查詢實現它,但是它正在掃描所有節點。

這是我嘗試過的查詢。

MATCH (p:Person)
REMOVE p.fatherName

除了此查詢,還有其他快速替代方法嗎?

無法通過Cypher來提高該查詢的性能。

您可以嘗試避免沒有父親名稱屬性的節點

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

我建議您編寫用於刪除該屬性的非托管擴展

例如

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM