Deleting indexed nodes in Neo4j

2020-04-07 04:06发布

问题:

In Neo4j, if I delete an indexed node do I have to remove that node from the index first or will the index be updated automatically?

Here is a small (untested) example:

val index = graphDb.index()
val someIdx = index.forNodes("someIdx")
val someNode = graphDb.createNode()
someIdx.add(someNode, "key", "value")

And then:

//remove from someIdx???
someNode.delete()

回答1:

When you delete a node, you have to remove the index first. If you want to remove all mentions of a node from the index, see below:

    IndexManager indexManager = db.index();
    Index<Node> index = indexManager.forNodes("indexName");
    index.remove(node);