0
votes

I have done a lot of reading by I can't seem to find the answer on this. If there's a duplicate post somewhere please point me to it!

Anyways, here it goes.

I'm trying to import data into Neo4J and create the relationships in order to easily graph the data. I was able to import the data without a problem using the LOAD CSV WITH HEADERS command now I'm not sure how to create the relationship piece.

My CSV/Table looks like this

source  target  action
172.x.x.x   172.y.y.y  accept
172.x.x.x   172.y.y.y  drop

All the data ends up in the same database and "table"

My goal is to have the following relationship scheme:

"Source"-------[action]------->"Target"

My first attempt was:

START n=node(*)
WHERE HAS(n.source) AND HAS(n.destination)
CREATE (n)-[:CONNECTS_TO]->(n)

I could not see the relationship at all after running this even though the browser shell said that it did create them and besides this does not take care of the "action" piece.

Any help would be appreciated.

1
Did you create separate nodes for source/target while importing? More details about your structure would be good.Eve Freeman
can you share your load-csv statement? Perhaps create a graphgist, like I did here? neo4j.org/graphgist?cace2732effa846d9fc2 source is: gist.github.com/jexp/cace2732effa846d9fc2Michael Hunger
There seem to be multiple issues with this (like you creating a reflexive relationship from n to n). Also it seems you're assuming a single node has both a source AND a destination. I would think that your relationships would have those, not your nodes. People will need to see your load information before we can help.FrobberOfBits

1 Answers

1
votes

You can load CSV into Neo4j by using following command

 load csv with headers from "file:///file_path" as input
 match (from:Node {source: input .source}),(to:Node {target:input.target})
 create (from)-[:RELATION  {type: input.action }]->(to)

*Note: You have to mention your lable name in the above query by replacing "Node".