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 需要更长的时间才能执行,但我试图避免插入的节点重复。

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

谢谢

-

-医学博士。

尝试将查询拆分为多个较小的查询。效果更好,更易于管理。此外,在使用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

最新更新