Skip to content
tseidler edited this page Sep 29, 2015 · 6 revisions
@neo.batch [:get_node, node1], [:get_node, node2]                        # Gets two nodes in a batch
@neo.batch [:create_node, {"name" => "Max"}],
           [:create_node, {"name" => "Marc"}]                            # Creates two nodes in a batch
@neo.batch [:set_node_property, node1, {"name" => "Tom"}],
           [:set_node_property, node2, {"name" => "Jerry"}]              # Sets the property of two nodes
@neo.batch [:reset_node_properties, node,
            {"name" => "Marc", "weight" => 250}]                         # Reset multiple node properties
@neo.batch [:create_unique_node, index_name, key, value,
             {"age" => 33, "name" => "Max"}]                             # Creates a unique node
@neo.batch [:get_node_relationships, node1, "out"],
           [:get_node_relationships, node2, "out"]                       # Get node relationships in a batch
@neo.batch [:get_relationship, rel1],
           [:get_relationship, rel2]                                     # Gets two relationships in a batch
@neo.batch [:create_relationship, "friends",
             node1, node2, {:since => "high school"}],
           [:create_relationship, "friends",
             node1, node3, {:since => "college"}]                        # Creates two relationships in a batch
@neo.batch [:create_unique_relationship, index_name,
             key, value, "friends", node1, node2]                        # Creates a unique relationship
@neo.batch [:reset_relationship_properties, rel, 
            {"since" => "college", "dated" => "yes"}]                    # Reset multiple relationship properties
@neo.batch [:get_node_index, index_name, key, value]                     # Get node index
@neo.batch [:get_relationship_index, index_name, key, value]             # Get relationship index
@neo.batch [:add_label, node, "label"]                                   # Add the label "label" to node

@neo.batch *[[:create_node, {"name" => "Max"}],
             [:create_node, {"name" => "Marc"}]]                         # Use the Splat (*) with Arrays of Arrays

Refer back to earlier results of a batch using the {n} notation:

@neo.batch [:create_node, {"name" => "Max"}],
           [:create_node, {"name" => "Marc"}],                           # Creates two nodes and index them
           [:add_node_to_index, "test_node_index", key, value, "{0}"],
           [:add_node_to_index, "test_node_index", key, value, "{1}"],
           [:create_relationship, "friends",                             # and create a relationship for those
             "{0}", "{1}", {:since => "college"}],                       # newly created nodes
           [:add_relationship_to_index,
             "test_relationship_index", key, value, "{4}"]               # and index the new relationship

See the Neo4j documentation for Batch operations documentation.

Please see the specs for more examples.

Clone this wiki locally