我刚刚开始使用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长,但我正在努力避免使用insert操作重复节点。
关于我应该改变什么或者如何改进这一点,有什么想法或建议吗?
谢谢,
--MD。
发布于 2017-05-25 05:27:04
尝试将查询拆分为多个较小的查询。效果更好,更易于管理。此外,在使用MERGE时,您通常需要在单个属性上执行此操作,例如人的电子邮件或其他独特的东西,然后使用ON CREATE SET。应该紧扣查询。看起来像这样:
MERGE (contact:Contact {email: line.EmailAddress})
ON CREATE SET contact.phoneNumber = line.TelephoneNumber在person中,没有一个唯一的属性,您可以使用多个属性的组合,但要知道,您在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.FeetIncheshttps://stackoverflow.com/questions/44168443
复制相似问题