Hi i'm trying to import some data from CSV files in Neo4j 2.3.1. I've already imported some nodes of type :Author and :Article.
The Author node is composed of properties like:
- key -> String
- principal_name -> String
- alias -> Collection of String
- ........
I've also added index on principal_name, alias and key.
The problem comes when I try to import the relationships between nodes of type Article and Author.
The CSV has this type of structure:
articleKey,authorName
Has a naive solution i've tried to create the relationship using a query like this one:
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///myPath.csv" AS line
MATCH (art:Article{key: line.key1})
MATCH (auth:Author) WHERE line.key2 IN (auth.alias)
CREATE UNIQUE (auth)-[:AUTHOR_OF]->(art);
The query is painfully slow because the second MATCH is really slow as i discovered using the profiler. It takes 10-12 seconds to create every relation because i've many Authors in the db(around 1000000).
So i'm looking for a way to execute a query like this one to get a faster execution(is an example to illustrate the structure that i want to obtain):
MATCH (auth:Author{principal_name: line.key2})
IF auth null THEN
MATCH (auth:Author) WHERE line.key2 IN (auth.alias)
END
There is a way to do that with Cypher ?