Hello I was trying to import some data in csv file to neo4j in my ubuntu 12.04.
The csv file is a two column data file with no header its format is like:
12ffew3213,232rwe13
12ffew3213,5yur2ru2r
rwerwerw3,432rwe13
rwerwerw3,5yur2ru2r
the thing is the data in row 0 and row 1 is not unique, for example the data may be 3000 lines and only has 100 unique row0 value and 300 unique row1 value.
And I want to build a graph with unique 100 row0 nodes and 300 row1 nodes and 3000 relationships between those nodes(if 12ffew3213,232rwe13 appears twice there are 2 edges).
Since I am new to neo4j and Cypher. After I tried with CREATE and MERGE for a while I still cannot build UNIQUE nodes. I used something like
LOAD CSV FROM 'file:///home/nate/Downloads/file.csv' AS line
MERGE (:A { number: toString(line[0])})-[:LIKES]->(:B { ID: toString(line[1])})
Any ideas??Thanks ahead!
In Neo4j to create relationship between nodes you have to use the CREATE statement like we used to create nodes. lets create relation between two already created nodes.
To import data from a CSV file into Neo4j, you can use LOAD CSV to get the data into your query. Then you write it to your database using the normal updating clauses of Cypher. A new node with the Artist label is created for each row in the CSV file.
Properties are stored as a linked list of property records, each holding a key and value and pointing to the next property. Each node and relationship references its first property record. The Nodes also reference the first relationship in its relationship chain. Each Relationship references its start and end node.
The Neo4j property graph database model consists of: Nodes describe entities (discrete objects) of a domain. Nodes can have zero or more labels to define (classify) what kind of nodes they are. Relationships describes a connection between a source node and a target node.
Here's what you do.
LOAD CSV FROM 'file:///home/nate/Downloads/file.csv' AS line
MERGE (n:A {number : line[0]})
WITH line, n
MERGE (m:B {ID : line[1]})
WITH m,n
MERGE (n)-[:LIKES]->(m);
You first create or match the :A
node, then create or match the :B
node, then create or match the relationship. The WITH
clauses collect the results at each point in the sequence to use in the next. To find out more about WITH
clauses, read Section 9.5 in the Neo4j Manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With