简体   繁体   中英

Correctly importing CSV File into Neo4j database

I am currently trying to import a csv file into neo4j. Now for example lets see the following file:

node1,node2
   value1,value2
   value2,value3
   value1,value2

Now what I am trying is to import those lines so that nodes 1 and 2 will be connected, while identical nodes only exist once. So I guess I will need to do the MERGE command which seems to work with the following CQL Request:

LOAD CSV WITH HEADERS FROM "file:///test_text.csv" AS line 
   MERGE (u :word { value: line.node1 }) 
   MERGE (h :word { value: line.node2 }) 
   MERGE (u)-[t :digram]->(h)

Now I want to achieve, that connections between 2 nodes, which occur multiple times in my csv file (like value1 to value 2 in the example above) are represented by an attribute "count" in the corresponding connection. So the connection between value1 and value2 has a attribute count=2.

I have tried to do that by appending the following line:

ON MERGE SET t.count = t.count + 1 ON CREATE SET t.count = 1

But that throws a syntax error. I am kind of lost at the moment and I am hoping you guys could help. Thank you very much.

这里只是一个小错误,它是ON MATCH SET ,而不是ON MERGE SET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM