dsTny
dsTny

Reputation: 150

Neo4j import data with queries

I searched in this forum and googled but I can't find a solution for my special problem. I have to create a new graph database (neo4j, cypher) and I have to create many data. Something like:

CREATE (:Mitglied { userID:1, vorname:"Jennifer", nachname:"Koch", geburtstag:"1977-12-11" }),
(:Mitglied { userID:2, vorname:"Lina", nachname:"Hansen", geburtstag:"1984-04-08" }), 
(:Mitglied { userID:3, vorname:"Paul", nachname:"Brandt", geburtstag:"1956-08-13" }), 
(:Mitglied { userID:4, vorname:"Sophie", nachname:"Peters", geburtstag:"1972-12-24" }), 
(:Mitglied { userID:5, vorname:"Manuel", nachname:"Graf", geburtstag:"1996-02-06" }),
...

So I tried to execute the shell batch (Neo4jShell.bat) with C#, copy & paste with some data into webadmin. Without success :( My code (start a new process and used inputstream for inserting every line) stopped after short time, nothing happened (either with the data nor with the program). Webadmin needs loooooong time for only 500 Creates. I have 2,100,000 Creates...

So can anybody of you guys help me and say what I can do? I haven't got any idea at the moment :( It is for study, so importing relational database is not a solution - the data must be created with queries.. But because of the mass of data it should happend automatically ;)

Thank you very much!

Upvotes: 1

Views: 840

Answers (2)

Skive
Skive

Reputation: 1

The solution to this problem that I found was manually executing queries in C#. I had a database of university students. Here's my code:

StringBuilder query_text = new StringBuilder();
query_text.Append("LOAD CSV WITH HEADERS FROM \"file:C:/.../students.csv\" AS csvLine ");
query_text.Append("MERGE(faculty: Faculty { name: csvLine.faculty}) ");
query_text.Append("MERGE(university: University { name: csvLine.university }) ");
query_text.Append("CREATE(student: Student { studentid: csvLine.student_id, name: csvLine.name, surname: csvLine.surname, address: csvLine.address, faculty: csvLine.faculty, university: csvLine.university}) ");
query_text.Append("CREATE(student) -[:STUDIES]->(faculty) ");
query_text.Append("CREATE(faculty) -[:OF]->(university)");
CypherQuery query = new CypherQuery(query_text.ToString(), new Dictionary<string, object>(), CypherResultMode.Set);
try {
    ((IRawGraphClient)client).ExecuteGetCypherResults<Studentas>(query);
}
catch(Exception e){ }

Upvotes: 0

Nicholas
Nicholas

Reputation: 7521

I see in your comment you're using C#, but are you versed in Java? If so, you can use the batch inserter, which is meant for this type of large, one time ingestion.

If not, is using a List of Maps any faster?

Upvotes: 2

Related Questions