0

我刚刚开始使用 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 需要更长的时间,但我试图避免插入重复的节点。

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

谢谢,

——医学博士。

4

1 回答 1

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
于 2017-05-24T21:27:04.117 回答