2

The sample is taken, but modified, from this example: http://neo4j.com/docs/2.2.2/cypherdoc-importing-csv-files-with-cypher.html

USING PERIODIC COMMIT 500 LOAD CSV 
WITH HEADERS FROM "http://neo4j.com/docs/2.2.2/csv/import/roles.csv" AS csvLine 
MATCH (person:Person { id: toInt(csvLine.personId)}),(movie:Movie { id: toInt(csvLine.movieId)}) 
CREATE (person)-[:csvLine.role { role: csvLine.role }]->(movie)

The above doesn't work since I try to use the data from the CSV-file to define the relationship type, which doesn't appear to be alloved. Or is it because the data in the CSV-file contains space?

Tomas Jansson
  • 22,767
  • 13
  • 83
  • 137

2 Answers2

1

This isn't possible as far as I know. Is it very many relationship types? If not, you could do something like this:

USING PERIODIC COMMIT 500 LOAD CSV 
WITH HEADERS FROM "http://neo4j.com/docs/2.2.2/csv/import/roles.csv" AS csvLine
WHERE csvLine.role = 'VALUE'
MATCH (person:Person { id: toInt(csvLine.personId)}),(movie:Movie { id: toInt(csvLine.movieId)}) 
CREATE (person)-[:VALUE { role: csvLine.role }]->(movie)

Obviously you'd need to copy/paste that bit for as many unique values as you have. I've not tried this before so you might need a WITH after (and maybe before?) the WHERE

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • That's what I expected. I would rather have the relationship tell me what it is instead of a property on the relationship. Thanks for your reply. – Tomas Jansson Jun 01 '15 at 14:07
  • Yeah, certainly. The other thing to keep in mind is the `neo4j-import` command. That lets you define a CSV in a certain format and will also allow you to specify the type as one of the columns in the CSV. The only catch is that you'll probably need to transform your CSV some. http://neo4j.com/docs/stable/import-tool.html – Brian Underwood Jun 01 '15 at 15:07
0

See this post for an answer to the question.

Incase the link didn't work, read about APOC Procedure. More specifically, apoc.create.relationship().

USING PERIODIC COMMIT 500 LOAD CSV 
WITH HEADERS FROM "http://neo4j.com/docs/2.2.2/csv/import/roles.csv" AS csvLine 
MATCH (person:Person { id: toInt(csvLine.personId)}),(movie:Movie { id: toInt(csvLine.movieId)}) 
WITH person, movie, csvLine
CALL apoc.create.relationship(person, csvLine.role, {role: csvLine.role}, movie) YIELD rel
RETURN *
alili2050
  • 96
  • 7