Question

When you add an indexed node in py2neo 1.6.0, you have two options:

graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

Option 1:

index = graph_db.get_or_create_index('Myindex')
indexed_node = index.get_or_create('key', 'value', {node props})

Option 2:

index = graph_db.get_or_create_index('Myindex')
indexed_node = graph_db.get_or_create_indexed_node('Myindex', 'key', 'value', {node props})

I.e. you can add the node via the Index or via the GraphDatabaseService.

Does it make a difference which one I use? Or are these just wrappers for the same function?

Was it helpful?

Solution

Both the options you show will achieve the same result and are almost idenitical. In Option 2, however, your first line is redundant. The graph_db.get_or_create_indexed_node method is a shortcut that creates both the index (if it does not already exist) and the node in a single call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top