Neo4j Adding multiple CSV in one query - neo4j

I have a folder of csv files like this - "1232422.csv"
headers:
"ID","Name","ScreenName","location","Friends","Followers","Verified","Description","URL","Created_At"
there are 1500 files, with the filename having a "follows" relation with the rows of the csv file : (filename)-[follows]-(csv_row)
What is the best way to upload all of the data to my neo4j Graph?

Assuming that the import config settings are correct, you can pass the list of filenames (e.g., ["1232422", "1232423", ...]) as a filenames parameter to this query:
UNWIND $filenames AS filename
LOAD CSV WITH HEADERS FROM "file:///"+filename+".csv" AS data
CREATE (f:File {filename:filename})-[:FOLLOWS]->(r:Row)
SET r.csv_row = data

Related

Neo4J - unable to create relationships (30,000)

I've got two csv files Job (30,000 entries) and Cat (30 entries) imported into neo4j and am trying to create a relationship between them
Each Job has a cat_ID and Cat contains the category name and ID
after executing the following
LOAD CSV WITH HEADERS FROM 'file:///DimCategory.csv' AS row
MATCH (job:Job {cat_ID: row.cat_ID})
MATCH (cat:category {category: row.category})
CREATE (job)-[r:under]->(cat)
it returns (no changes, no records)
I received a prompt recommending that I index the category and so using
Create INDEX ON :Job(cat_id); I did, but I still get the same error
How do I create a relationship between the two?
I am able to get this to work on a smaller dataset
You are probably trying to match on non-existing nodes. Try
LOAD CSV WITH HEADERS FROM 'file:///DimCategory.csv' AS row
MERGE (job:Job {cat_ID: row.cat_ID})
MERGE (cat:category {category: row.category})
CREATE (job)-[r:under]->(cat)
Have a look in your logs and see if you are running out of memory.
You could try chunking the data set up into smaller pieces with Periodic Commit and see if that helps:
:auto USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///DimCategory.csv' AS row
MATCH (job:Job {cat_ID: row.cat_ID})
MATCH (cat:category {category: row.category})
CREATE (job)-[r:under]->(cat)

How can I create two node types from one csv in neo4j?

I only have this csv:
nameaddress.csv
and I want to create this network in neo4j =
How I can do this easily ?
The answer is:
LOAD CSV WITH HEADERS FROM 'csvFilePath' as row MERGE(people: People {name:row.name}) MERGE(address:Address {name:row.address})
MERGE (people)-[r:WENT_TO]->(address) RETURN people,address;

Error in importing data into neo4j via csv

I am new to neo4j.
I can't figure out what I am doing wrong?, please help.
LOAD CSV WITH HEADERS FROM "file:///C:\Users\Chandra Harsha\Downloads\neo4j_module_datasets\test.csv" as line
MERGE (n:Node{name:line.Source})
MERGE (m:Node{name:line.Target})
MERGE (n)-[:TO{distance:line.dist}]->(m)
Error message:
Invalid input 's': expected four hexadecimal digits specifying a unicode character (line 1, column 41 (offset: 40))
"LOAD CSV WITH HEADERS FROM "file:///C:\Users\Chandra Harsha\Downloads\neo4j_module_datasets\test.csv" as line"
You've got two problems here.
The immediate error is that the backslashes in the path are being seen as escape characters rather than folder separators - you either have to escape the backslashes (by just doubling them up) or use forward-slashes instead. For example:
LOAD CSV WITH HEADERS FROM "file:///C:\\Users\\Chandra Harsha\\Downloads\\neo4j_module_datasets\\test.csv" as line
MERGE (n:Node{name:line.Source})
MERGE (m:Node{name:line.Target})
MERGE (n)-[:TO{distance:line.dist}]->(m)
However - Neo4j doesn't allow you to load files from arbitrary places on the filesystem anyway as a security precaution. Instead, you should move the file you want to import into the import folder under your database. If you're using Neo4j Desktop, you can find this by selecting your database project and clicking the little down-arrow icon on 'Open Folder', choosing 'Import' from the list.
Drop the CSV in there, then just use its filename in your file space. So for example:
LOAD CSV WITH HEADERS FROM "file:///test.csv" as line
MERGE (n:Node{name:line.Source})
MERGE (m:Node{name:line.Target})
MERGE (n)-[:TO{distance:line.dist}]->(m)
You can still use folders under the import directory - anything starting file:/// will be resolved relative to that import folder, so things like the following are also fine:
LOAD CSV WITH HEADERS FROM "file:///neo4j_module_datasets/test.csv" as line
MERGE (n:Node{name:line.Source})
MERGE (m:Node{name:line.Target})
MERGE (n)-[:TO{distance:line.dist}]->(m)

How to specify a separate header file inside apoc.load.csv?

I'm migrating data from RDBMS to Neo4j. I'm using 'neo4j-admin import' tool for bulk import by loading a csv dump. In order to accomodate live updates, I'm again getting the csv dump from RDBMS. Now, I'm using 'apoc.load.csv'.
I've my data in one file, say 'upd_product.csv'
And I've the headers in 'product_h.csv'
Now I want to use apoc.load.csv
Call apoc.load.csv('/upd_product.csv') yield map, list
Match (p: Product {id: line[0]})
Set p = map
In order to have this map, I need to specify the headers, and there exists no documentation on how to do that.
Please help me in this context.
Thanks in advance.
Just prepend the contents of product_h.csv (presumably a single line) to the beginning of upd_product.csv. Afterwards, you can just do this (assuming the header value for the first column is id):
CALL apoc.load.csv('/upd_product.csv') YIELD map
MATCH (p:Product {id: map.id})
SET p = map

How to import csv data to create nodes with specified properties in neo4j

I have to create 30+ nodes with below CSV data as properties,
id,name,skill,cur_company,pre_company,college,location
1,"pavan","java","CGI","CSC","JNTU","HYDERABAD"
2,"ravi","java","TCS","CSC","SGPL","DELHI"
...
How to create nodes by importing above data. like,
u1:User {id:1,name:"pavan",skill:"java",cur_company:"CGI",prev_company:"CSC",location:"HYDERBAD"}
u2:User {id:2,name:"ravi",skill:"java",cur_company:"TCS",prev_company:"CSC",location:"DELHI"}
There is a dedicated LOAD CSV command in Cypher:
load csv with headers from "file-url" as data
create (u:User {data}}
or
load csv with headers from "file-url" as data
create (u:User {id:data.id, name:data.name, ....}}
Before applying above command , do following changes in neo4j.conf file:
Comment the #dbms.security.allow_csv_import_from_file_urls=true line
and
uncomment the dbms.directories.import=import line

Resources