Prev |  | Next

## 5.6. Update

| Important
To update an index entry, old one must be removed and a new one added.

Remember that a node or relationship can be associated with any number of key-value pairs in an index, which means that you can index a node or relationship with many key-value pairs that have the same key. In the case where a property value changes and you’d like to update the index, it’s not enough to just index the new value - you’ll have to remove the old value as well.

Here’s a code example for that demonstrates how it’s done:

    // create a node with a property
    Node fishburn = graphDb.createNode();
    fishburn.setProperty( "name", "Fishburn" );
    // index it
    actors.add( fishburn, "name", fishburn.getProperty( "name" ) );
    // update the index entry
    actors.remove( fishburn, "name", fishburn.getProperty( "name" ) );
    fishburn.setProperty( "name", "Laurence Fishburn" );
    actors.add( fishburn, "name", fishburn.getProperty( "name" ) );

Copyright © 2011 Neo Technology

Prev | Up | Next
| Home |