0
votes

Is CSV the only options to speed up my bulk relationships creation?

I read many articles in internet, and they all are telling about CSV. CSV will definitely give me a performance boost (could you suppose how big?), but I'm not sure I can store data in CSV format. Any other options? How much I will get from using Neo4J 3 BOLT protocol?

My program

I'm using Neo4j 2.1.7. I try to create about 50000 relationships at once. I execute queries in batch of size 10000, and it takes about 120-140 seconds to insert all 50000.

My query looks like:

MATCH (n),(m) 
WHERE id(n)=5948 and id(m)=8114 
CREATE (n)-[r:MY_REL {
    ID:"4611686018427387904",
    TYPE: "MY_REL_1"
    PROPERTY_1:"some_data_1",
    PROPERTY_2:"some_data_2",
    .........................
    PROPERTY_14:"some_data_14"
}]->(m) 
RETURN id(n),id(m),r
1

1 Answers

2
votes

As it is written in the documentation:

Cypher supports querying with parameters. This means developers don’t have to resort to string building to create a query. In addition to that, it also makes caching of execution plans much easier for Cypher.

So, you need pack your data as parameters and pass with cypher query:

UNWIND {rows} as row
MATCH (n),(m) 
WHERE id(n)=row.nid and id(m)=row.mid
CREATE (n)-[r:MY_REL {
    ID:row.relId,
    TYPE:row.relType,
    PROPERTY_1:row.someData_1,
    PROPERTY_2:row.someData_2,
    .........................
    PROPERTY_14:row.someData_14
}]->(m) 
RETURN id(n),id(m),r