Note that there are some explanatory texts on larger screens.

plurals
  1. POpy2neo: batch create indexed node with multiple key:value pairs
    primarykey
    data
    text
    <p>With </p> <pre><code>batch = neo4j.WriteBatch(graph_db) for n in nodes: batch.create_indexed_node_or_fail(index, key, value, {node properties}) batch.submit() </code></pre> <p>you can easily create indexed nodes in a batch.</p> <p>But how can I create a node in a batch and add multiple key:value pairs at the same time? Or add the node to multiple indices? </p> <p>One idea I thought of is to first create the nodes and then add them to the indices in a second batch:</p> <pre><code>for n in nodes: batch.create({node properties}) results = batch.submit() for r in results: batch add node to index1 batch add node to index2 batch.submit() </code></pre> <p>But this seems to complicated. Py2neo is so amazing, there must be an easier way.</p> <hr> <p>Based on Nigel's answer, I tried to this for a list of nodes:</p> <pre><code>batch = neo4j.WriteBatch(graph_db) item_in_batch = 0 for n in list_of_nodes: batch.create(n) # this works, all nodes are created batch.add_indexed_node("people", "key", "value from n", item_in_batch) batch.add_indexed_node("people", "key2", "other value from n", item_in_batch) i += 1 batch.submit() </code></pre> <p>Some nodes end up in my index, but not all. When I search the index for ('key:value-from-n") it returns a node but not the correct one. How can I access the 'internal' ID of the nodes when I try to add them to an index? </p> <hr> <p>I tried the (currently testing) version 1.6.0 of py2neo and it works! </p> <pre><code>n = batch.create(node) </code></pre> <p>now returns a request object which can be used within the batch to refer to the node.</p> <p>An example is in the <a href="http://book.py2neo.org/en/release-1.6.0/batches/#py2neo.neo4j.WriteBatch.create" rel="nofollow">docs for 1.6.0</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload