Reputation: 12557
Given
I've to insert a hughe set of data into neo4j. Currently I created methods for
a) Insert a batch of nodes
public Task AddNodesAsync<T>(List<T> nodes)
{
return client.Cypher.Create("(n:" + typeof(T).Name + " {nodes})").WithParams(new
{
nodes
}).ExecuteWithoutResultsAsync();
}
b) Related 2 Kind of nodes
public async Task LinkVertices<TSource, TTarget>(Expression<Func<TSource, TTarget, bool>> join, string relationName)
{
string sourceName = typeof(TSource).Name;
string targetName = typeof(TTarget).Name;
await client.Cypher
.Match(string.Format("({0}:{0})", sourceName), string.Format("({0}:{0})", targetName))
.Where(join)
.Create(string.Format("{0}-[:{2}]->{1}", sourceName, targetName, relationName))
.ExecuteWithoutResultsAsync();
}
Now I call AddNodesAsync<T>
2 Times and after that i call the second method to link them. Likethis:
AddNodesAsync(Projects);
AddNodesAsync(myCustomers);
LinkVertices<Projects,Customer>((project,customer) => project.customerId == customer.id,"projectsOfCustomer");
This works fine but i', asking my self if this is a good solution. I can see that especially the linking process is very slow.
So my question is
What is the recommended way for an initialization of neo4j ?
Show I Use the C# Api ? The restfull api ? Or event the csv importer? And second question is there a way to insert both batches with the links in one step ? I would expected this may be faster.
Upvotes: 0
Views: 149
Reputation: 66967
You should look into using the Import tool if you want to quickly import a huge amount of data into a brand new neo4j DB.
Upvotes: 1