Neo4J CSV Relations

I am new to Neo4J and I have a simple CSV with source and remote IP addresses. I would like to create a link between nodes with the same shortcuts.

Something like ... source_ip -> ALERTS -> dest_ip, or vice versa.

"dest_ip","source_ip" 
"130.102.82.16","54.231.19.32" 
"130.102.82.116","114.30.64.11" 
"130.102.82.116","114.30.64.11" 
...

LOAD CSV WITH HEADERS 
FROM "file:///Users/me/Desktop/query_result.csv" AS csvLine  
CREATE (alert:Alert { source_ip: csvLine.source_ip, dest_ip: csvLine.dest_ip})

MATCH (n:Alert) RETURN n LIMIT 25

dest_ip 130.102.82.16 source_ip 54.231.19.32

....

It works great. My question is, how do I create a relationship between labels inside alerts? I tried and failed. I assume that I need to configure separate nodes for Source and Dest, and then link them, just do not know how to do this.

Thanks in advance!

World Tom

+4
source share
2 answers

First create a constraint like this to guarantee uniqueness and speed up the operation MERGE.

CREATE CONSTRAINT ON (a:Alert) ASSERT a.ip IS UNIQUE;

CREATE, , MERGE , :

LOAD CSV WITH HEADERS 
FROM "file:///Users/me/Desktop/query_result.csv" AS csvLine  
MERGE (node1:Alert { ip: csvLine.source_ip })
MERGE (node2:Alert { ip: csvLine.dest_ip })
MERGE (node1)-[r:ALERT]->(node2)

MERGE, , . IP- , node , , , IP-, MERGE CREATE

+6

,

(: ) - [: ] → (: )

Cypher

LOAD CSV WITH HEADERS FROM "file:///Users/me/Desktop/query_result.csv" AS csvLine 
CREATE (source:Source { ip: csvLine.source_ip })-[:ALERTS]->(dest:Destination { ip: csvLine.dest_ip})
+2

Source: https://habr.com/ru/post/1614626/


All Articles