First of, I checked previous questions and found some answers but couldn't transfer the solution to my exact problem. The question which comes the closest to my problem is this one here.
My problem:
I have a large .csv file which contains interactions from different ids with a timestamp. The columns are source, target and servertime and a row looks like this:
B_655, B_632, 2020-07-03 00:11:48.828
As the different devices measure the connections in both directions it is common that the same connection but with switched source and target occure at nearly the same time:
B_632, B_655, 2020-07-03 00:11:47.258
Also the different devices measure every 15s, therefore a longer connection (an interaction which lasted 45s) will have 3 different rows.
B_655, B_632, 2020-07-03 00:11:48.828
B_655, B_632, 2020-07-03 00:12:03.828
B_655, B_632, 2020-07-03 00:12:18.828
I know want to have all of this data in my Neo4j database and have bigger weights on the connections between two ids (source & target) which occured more often, but also be able to investigate the graph with regard to the time. For example I want to query how many new connection id B_649 had between date X and date y.
The IDs are unique but as I stated earlier they can appear in the source-column as well as in the target-column.
In was able to read in the data in neo4J browser but struggled with establishing the connection. A Cypher-Query which worked to read my csv file was as follows:
LOAD CSV WITH HEADERS FROM 'file:///connections.csv' AS row
WITH row.source as sourcetag, datetime(replace(row.servertime, ' ', 'T')) as timestamp, row.target as beacon
RETURN timestamp, sourcetag, beacon
limit 3
Does somebody know a way to import such a social-network into neo4j? Many thanks in advance!
First, you want to create a unique constraint for the nodes. I will assume that this is a
(:User)-[:INTERACTS]->(:User)
but you can change it how you see fit later.
CREATE CONSTRAINT ON (u:User) ASSERT u.id IS UNIQUE;
Now you can go ahead and import the csv file:
LOAD CSV WITH HEADERS FROM 'file:///connections.csv' AS row
WITH row.source as sourcetag,
datetime(replace(row.servertime, ' ', 'T')) as timestamp,
row.target as beacon
MERGE (s:User{id:sourcetag})
MERGE (t:User{id:beacon})
CREATE (s)-[:INTERACTION{date:timestamp}]->(t)
You can change the node labels and relationship types how you see fit.