简体   繁体   中英

Questions regarding importing csv into neo4j

I have three questions regarding importing csv:

  1. Is it possible to make the command to ignore the first line in the csv files? (As there are many files to import, it is inconvenient to change all of them)
  2. Is it possible to make the property of a relationship or node to be null if the corresponding property in csv files is empty?
  3. Is it possible to have the same type of nodes with different (number of) properties?

1) Yes you can use SKIP as well in LOAD CSV :

LOAD CSV WITH HEADERS FROM "file:///dummyfile.csv" AS row
WITH row
SKIP 1
MERGE (n:Node {id: row[0]})

2) If the csv column value is NULL, then the corresponding property value will be null as well. If it is empty, then the property will not be created

Assume the following CSV :

id,title,desc
1,title 1,desc1
2,,desc 2

And the following LOAD CSV :

LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/ikwattro/ed85bfc98c9298924c154ecf3e0ab2aa/raw/54a9303c365a7698c87728d458f8de703a9c22e1/load.csv" AS row
CREATE (n:Post {id: row['id'], title: row['title'], description: row['desc']})

This would create the following :

╒══════════════════════════════════════════════════╕
│"n"                                               │
╞══════════════════════════════════════════════════╡
│{"description":"desc1","id":"1","title":"title 1"}│
├──────────────────────────────────────────────────┤
│{"description":"desc 2","id":"2"}                 │
└──────────────────────────────────────────────────┘

3) Yes, Neo4j being schemaless you don't need to have the same number of properties on nodes with the same label

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