Search code examples
neo4jneo4jphp

Should we update indexes after node update in neo4jphp?


According to this manual https://github.com/jadell/neo4jphp/wiki/Indexes we should worry about adding and removing nodes to indexes by ourselves.

OK, I'm adding nodes to indexes after creating them. But should I also update the indexes when I change some of the node's properties?


Solution

  • Neo4j has two indexing systems: The Legacy Indexes and Indexes.

    Legacy indexes

    This is a stand-alone indexing service that Neo4j ships with, and it gives you very little for free, it does not keep up to date with changes you make to the graph, other than lazilly removing items that you've deleted in the graph.

    If you want something in a legacy index, you must manually put it in there, and if you want it to reflect a change in the graph, you must manually update the index.

    The sole reason these indexes remain, other than for backwards compatibility, is that they support complex indexes like geo-spatial indexing and rich full text indexing functionality. These are not yet supported by the new Indexes.

    Read more about legacy indexes here: http://docs.neo4j.org/chunked/stable/indexing.html

    Indexes

    These were added in 2.0.0, and work the same way indexes do in relational databases - they are an optimization that you can introduce, and they are automatically kept in sync with the "primary" data, in our case, with changes with the graph.

    An Index is defined on a combination of a Label and a Property Key, and subsequent lookups on that Label/Property key combination will (if the query planner determines this is the most efficient thing to do) use that index.

    Read more about indexes here: http://docs.neo4j.org/chunked/stable/graphdb-neo4j-schema.html