py2neo: index.get_or_create() or graph_db.get_or_create_indexed_node()

StackOverflow https://stackoverflow.com/questions/18836106

  •  28-06-2022
  •  | 
  •  

Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top