Question

I want to insert some data into Neo4j using py2neo . Link to data file. I am new to Neo4j. Can someone tell me how to insert bulk data into Neo4j.Actually i want to do performance testing of Neo4j.....

I have tried this but this is just for small data set ...

from pprint import pprint
from py2neo import neo4j,node, rel
graph_db = neo4j.GraphDatabaseService()

def insert_data():
    die_hard = graph_db.create(
        node(name="Bruce Willis"),
        node(name="John McClane"),
        node(name="Alan Rickman"),
        node(name="Hans Gruber"),
        node(name="Nakatomi Plaza"),
        rel(0, "PLAYS", 1),
        rel(2, "PLAYS", 3),
        rel(1, "VISITS", 4),
        rel(3, "STEALS_FROM", 4),
        rel(1, "KILLS", 3),)
    pprint(die_hard)

insert_data()

error :

src/test/java/org/neo4j/batchimport/TestDataGenerator.java:3: error: package org.junit does not exist
import org.junit.Ignore;
                ^
src/test/java/org/neo4j/batchimport/TestDataGenerator.java:14: error: cannot find symbol
@Ignore
 ^
  symbol: class Ignore
2 errors
Was it helpful?

Solution 2

Not sure if this is the issue you're having, but when I tried your sample, I got errors on the [name=] syntax. What's being passed to the node() constructor is a dictionary. There are multiple syntax for the node() constructor, and I didn't see a syntax that matches the one your using. So, try using dictionary syntax like this:

node({"name": "Bruce Willis"})

Also, I'm not sure if you've configured a default neo4j url, but I had to specify a connection point url in my new4j.GraphDatabaseService() call.

So, your code would look like:

from pprint import pprint
from py2neo import neo4j, node, rel
graph_db = neo4j.GraphDatabaseService('http://localhost:7474/db/data')

def insert_data():
    die_hard = graph_db.create(
        node({"name": "Bruce Willis"}),
        node({"name": "John McClane"}),
        node({"name": "Alan Rickman"}),
        node({"name": "Hans Gruber"}),
        node({"name": "Nakatomi Plaza"}),
        rel(0, "PLAYS", 1),
        rel(2, "PLAYS", 3),
        rel(1, "VISITS", 4),
        rel(3, "STEALS_FROM", 4),
        rel(1, "KILLS", 3),)
    pprint(die_hard)

insert_data()

OTHER TIPS

I'd highly recommend you use the 'Geoff' format which stands for 'Graph Export Object File Format'.

In this method you basically generate a text file containing nodes and relationship information which is then used to populate the database in a batch insert.

The 'Load2Neo' module is used to batch insert the information.

Having used it, I can say it is extremely fast. Make sure you check out the simple documentation here. As long as you follow the syntax rules, you'll have a smooth experience with Geoff!

Geoff has been developed by Nigel Small, who also is the author of Py2Neo (the python driver for Neo4j). It you run into issues and want quick help, make sure you fire Nigel a tweet. He helps out!

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