neo4j: Cypher LOAD CSV with uuid

1.2k Views Asked by At

I am starting to work with LOAD CSV of Cypher for Neo4J to import larger csv-files into my DB. I would like to add to each imported node a unique ID (uuid) as a property.

My try was:

LOAD CSV FROM "file:..." AS csvLine
CREATE (c:Customer { uuid: {uuid}, name: csvLine[0], code: csvLine[1]})

Unfortunately I receive for each node the same UUID (although its a function that would normally generate the UUID new when called), it looks like the UUID is generated 1 time and then attached to each node while creating the node and parsing the csv-file.

Is there a way to generate a new UUID for each imported csv-line to mark the node?

Thanks for your hints from Balael

2

There are 2 best solutions below

5
On BEST ANSWER

Not sure where you've seen that {uuid} is a function. It is just using whatever you pass in as an parameter "uuid".

You'd have to generate a uuid when creating your CSV. In cypher there is currently no uuid() function.

One workaround that you could do is:

LOAD CSV FROM "file:..." AS csvLine
CREATE (c:Customer { name: csvLine[0], code: csvLine[1]})
SET c.id = id(c)
2
On

You could also use the GraphAware UUID Module.

All you would have to do is drop the framework jar and the uuid module jar into the plugins directory, add the following 2 lines into neo4j.properties, and restart Neo4j.

com.graphaware.runtime.enabled=true
com.graphaware.module.UIDM.1=com.graphaware.module.uuid.UuidBootstrapper

Any new node (no matter how it is created) will automatically get a UUID.