Neo4j - LOAD-CSV未创建所有节点

时间:2017-05-24 21:05:03

标签: neo4j load-csv

我刚刚开始使用Neo4J,我正在尝试使用LOAD CSV将一些数据加载到Neo4j 3.1中,并使用以下脚本:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///Fake59.csv" AS line
MERGE (person:Person {firstName: line.GivenName, middleInitial: line.MiddleInitial, lastName: line.Surname, title: line.Title,
gender: line.Gender, birthday: line.Birthday, bloodType: line.BloodType, weight: line.Pounds, height: line.FeetInches})
MERGE (contact:Contact {phoneNumber: line.TelephoneNumber, email: line.EmailAddress})
MERGE (person)-[:CONTACTED_AT]->(contact)
MERGE (color:Color {name: line.Color})
MERGE (person)-[:FAVORITE_COLOR]->(Color)
MERGE (address:Address {streetAddress: line.StreetAddress, city: line.City, zipCode: line.ZipCode})
MERGE (person)-[:LIVES_AT]->(address)
MERGE (state:State {abbr: line.State, name: line.StateFull})
MERGE (city)-[:STATE_OF]->(stage)
MERGE (country:Country {name: line.CountryFull, abbr: line.Country, code: line.TelephoneCountryCode})
MERGE (state)-[:IN_COUNTRY]->(country)
MERGE (credentials:Credentials {userName: line.Username, password: line.Password, GUID: line.GUID})
MERGE (person)-[:LOGS_in]->(credentials)
MERGE (browser:Browser {agent: line.BrowserUserAgent})
MERGE (person)-[:BROWSES_WITH]->(browser)
MERGE (creditCard:CreditCard {number: line.CCNumber, cvv2: line.CVV2, expireDate: line.CCExpires})
MERGE (person)-[:USES_CC]->(creditCard)
MERGE (creditCompany:CreditCompany {name: line.CCType})
MERGE (creditCard)-[:MANAGED_BY]->(creditCompany)
MERGE (occupation:Occupation {name: line.Occupation})
MERGE (person)-[:WORKS_AS]->(occupation)
MERGE (company:Company {name: line.Company})
MERGE (person)-[:WORKDS_FOR]->(company)
MERGE (company)-[:EMPLOYES]->(occupation)
MERGE (vehicle:Vehicle {name: line.Vehicle})
MERGE (person)-[:DRIVES]->(vehicle)

输入文件大约有50k行。它运行了几个小时,该过程没有完成,但在那之后,如果我查询数据库,我看到只创建了节点类型(Person)。如果我运行一个包含3个条目的较小文件,则只会创建所有其他节点和关系。

我已经更改了分配给Neo4j和JVM的内存量,但仍然没有成功。我知道MERGE需要比CREATE执行更长的时间,但我试图避免使用插入重复节点。

关于我应该改变什么或如何改进这一点的任何想法或建议?

谢谢,

- MD。

1 个答案:

答案 0 :(得分:0)

尝试将您的查询拆分为多个较小的查询。效果更好,更易于管理。此外,在使用MERGE时,您通常应该在单个属性上执行此操作,例如针对此人或某些内容的电子邮件,然后使用ON CREATE SET。应该紧固查询。看起来像这样:

MERGE (contact:Contact {email: line.EmailAddress})
ON CREATE SET contact.phoneNumber = line.TelephoneNumber

对于没有单一属性的人,您可以使用多个组合,但要知道您在MERGE中添加的每个属性都会降低查询速度。

MERGE (person:Person {firstName: line.GivenName, middleInitial: line.MiddleInitial, lastName: line.Surname}) 
ON CREATE SET person.title = line.Title, person.gender = line.Gender,
person.birthday = line.Birthday, person.bloodType = line.BloodType, 
person.weight = line.Pounds, person.height = line.FeetInches