Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-20-2022 01:52 AM - edited 09-20-2022 01:52 AM
Hi,
I would like to Split a row into two labels while importing the data with CSV. Whereas manufacturer node is already created and the split action will be done to connect a relationship between manufacturer and vehicle type.
I am trying something like this:
09-20-2022 12:33 PM - edited 09-22-2022 01:58 AM
Hi I'm not sure I understand your problem
I'm assuming you want to MATCH the first column with your existing manufacturer and then CREATE a Vehicle Type and also a relationship with it
WITH [["JEA1_Z21", "Bulker"], ["KLQ2_Z34", "Truck"]] as rows // you should change this to your LOAD CSV....
UNWIND rows AS row
WITH
row[0] AS manufacturer,
row[1] AS vehicleType
MATCH (m: Manufacturer { id: manufacturer})
WITH m, vehicleType
MERGE (v:VehicleType {id: vehicleType})
MERGE (m)-[:LOADS]->(v)
09-20-2022 09:52 PM
Hi @mochalla !
If I understand correctly you could try to do something like:
LOAD CSV FROM 'file:///file.csv' AS row
MERGE (v:Vehicle {type: row[1]})
MERGE (m:Manufacturer {code: row[0]})
MERGE (m)-[:LOADS]->(v)
You just have to move the file.csv (of course this would depend on your file name) with your data into the import folder of your Neo4j installation, if you are using Neo4j Desktop it should be accessible through the DBMS options menu.
Hope this helps!
09-21-2022 11:00 AM
Try this:
LOAD CSV WITH HEADERS FROM 'file:///xxx.csv' AS row
WITH row, row.` Manufacturer and Vehicle Type` as mvt
WITH row, split(mvt, "_") as mvt2
MERGE (a:Manufacturer {name: mvt2[0]})
MERGE (b:VehicleType {vehicle: mvt2[1], type: row.` Vehicle Type` })
MERGE (a)-[:LOADS]->(b)
All the sessions of the conference are now available online