neo4j加载csv非常慢

时间:2016-01-22 18:08:28

标签: neo4j cypher load-csv graphenedb

我正在尝试将CS​​V文件加载到GrapheneDB上托管的Neo4j数据库中。它在5000行的第一个文件上工作正常。完成此文件大约需要16秒。

我现在正在导入具有相同架构和相同行数的第二个文件。数据不同。 Cypher查询已运行超过30分钟,但仍未完成。我不知道它在做什么,为什么它这么慢。这是我的密码:

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM 'http://example.com/some.csv' AS line
Match (c:Customer {customerID: line.CustomerID}) 
MERGE (c)<-[r:DEPT_OF]-(dept:Dept { name: line.Category})
ON CREATE 
SET dept.name = line.Category, dept.deptID=line.DeptID, dept.createdDTS=1453478149463
MERGE (dept)<-[r1:IN_DEPT]-(pt:ProductType {name: dept.name}) 
ON CREATE 
SET pt.name = dept.name, pt.packQty = line.PackQty, pt.createdDTS = 1453478149463, 
pt.productTypeID = line.ProductTypeID
MERGE (pt)<-[r2:OF_TYPE]-(st:Style {name: line.Style})
ON CREATE 
SET st.name = line.Style, st.styleID = line.StyleID, st.styleNum = line.StyleNo, st.price = line.Price
MERGE (st)<-[r3:OF_STYLE]-(p:Product {productNum: line.UPC})
ON CREATE 
SET p.floorMin = line.MinFloor, p.floorMax = line.FloorMax, p.color = line.Color, p.createdDTS = 1453478149463,
p.size = line.Size, p.productID = line.ProductID;

对于来自我的csv的行:

UPC,Category,Style,StyleNo,Color,Size,MinFloor,MaxFloor,Price,ProductID,CustomerID,ProductType,PackQty,DeptID,StyleID,ProductTypeID,ProductID
33383605005,FRESH VEGETABLES,GREEN ONIONS 24/10 OZ,NA,NA,NA,0,0,1.79,,5f795a69-47cb-49c8-a334-0cf5d67be423,FRESH VEGETABLES,1,538a02c6-b6b7-4d0d-8dca-5ff3a513d59e,3e08dabb-415a-4826-86e8-44efb9813892,cc6a0f3c-1c05-44a0-b603-37cbbb60954e,3324b2b1-954a-4547-a82d-553be66d7b54
52867010005,FRESH VEGETABLES,GREEN ONIONS 24/10 OZ,NA,NA,NA,0,0,1.79,,5f795a69-47cb-49c8-a334-0cf5d67be423,FRESH VEGETABLES,1,edfa998f-3749-4d1f-bd96-3f4a5db0de67,fb11a8e5-de49-44da-924a-9ebc5f7f01d2,d47fd5d8-dbf0-4110-b701-543e6ed0ae40,28a9d206-96c6-4fe4-b528-84e446ba3c16

更新1:

我根据Nicole的回复添加了以下索引。

  1. CREATE INDEX ON:客户(customerID)
  2. 创建指数:部门(名称)
  3. CREATE INDEX ON:ProductType(name)
  4. CREATE INDEX ON:样式(名称)
  5. 创建INDEX ON:产品(productNum)
  6. 这有很多帮助,但是对于5K行仍然需要大约20秒。这是正常的吗?

    感谢任何帮助。

    更新2:

    基于@michael的回复,我进一步研究了一下,发现以下文章非常有用:

    http://graphaware.com/neo4j/2014/07/31/cypher-merge-explained.html

    更新3:

    我已将我的密码更新为以下内容以避免重复。我希望这看起来不错?

    USING PERIODIC COMMIT 500
    LOAD CSV WITH HEADERS FROM '...' AS line
    Match (c:Customer {customerID: line.CustomerID}) 
    MERGE (c)<-[r:DEPT_OF]-(dept:Dept { name: line.Category })
    ON CREATE 
    SET dept.name = dept.name, dept.deptID=line.categoryID, dept.createdDTS=1453742532269, dept.modifiedDTS = 1453742532269
    MERGE (c)<-[r22:DEPT_OF]-(dept)
    MERGE (dept)<-[r1:IN_DEPT]-(pt:ProductType {name: dept.name}) 
    ON CREATE 
    SET pt.name = dept.name, pt.packQty = line.PackQty, pt.createdDTS = 1453742532269, pt.productTypeID = line.ProductTypeID, pt.modifiedDTS = 1453742532269
    MERGE (c)<-[r2:DEPT_OF]-(dept)
    MERGE (dept)<-[r3:IN_DEPT]-(pt) 
    MERGE (pt)<-[r4:OF_TYPE]-(st:Style {name: line.Style})
    ON CREATE 
    SET st.name = line.Style, st.styleID = line.StyleID, st.styleNum = line.StyleNo, st.price = line.Price, st.modifiedDTS = 1453742532269, st.createdDTS = 1453742532269
    MERGE (c)<-[r5:DEPT_OF]-(dept)
    MERGE (dept)<-[r6:IN_DEPT]-(pt) 
    MERGE (pt)<-[r7:OF_TYPE]-(st)
    MERGE (st)<-[r8:OF_STYLE]-(p:Product {productNum: line.UPC})
    ON CREATE 
    SET p.floorMin = line.MinFloor, p.floorMax = line.FloorMax, p.color = line.Color, p.createdDTS = 1453742532269,p.modifiedDTS = 1453742532269, p.size = line.Size, p.productID = line.ProductID;
    

0 个答案:

没有答案