prateek3636
prateek3636

Reputation: 175

neo4j cypher query for csv import

I am importing data from csv and using neo4j2.1.1. I use following query to find node with index....

LOAD CSV FROM 'file:/tmp/test.csv' AS line Start

p = node:node_auto_index(mysqlPatientId = line[0])
set p.patDob = line[8]
return p;

But I tried a lot but always got error -------

SyntaxException: Invalid input 'l': expected whitespace, comment, "...string..." or a parameter (line 1, column 95)
"LOAD CSV FROM 'file:/tmp/10lpnew.csv' AS line Start p = node:node_auto_index(mysqlPatientId = line[0])"

thanks in advance..!!

Upvotes: 2

Views: 850

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

I guess LOAD CSV does not play nicely with legacy indexes. Therefore I suggest to set a label on all nodes having a mysqlPatientId:

MATCH (n) WHERE HAS(n.mysqlPatientId) SET n :Patient

If you have a large number of these nodes, consider using SKIP and LIMIT to use a reasonable transaction size, e.g.

MATCH (n) WHERE HAS(n.mysqlPatientId) SET n :Patient SKIP 0 LIMIT 20000
MATCH (n) WHERE HAS(n.mysqlPatientId) SET n :Patient SKIP 20000 LIMIT 20000
MATCH (n) WHERE HAS(n.mysqlPatientId) SET n :Patient SKIP 40000 LIMIT 20000

When done, create a schema index:

CREATE INDEX ON :Patient(mysqlPatientId)

Next is switching of auto indexing in neo4j.properties.

Importing CSV should no work like this:

LOAD CSV FROM 'file:/tmp/test.csv' AS line Start
MERGE (p:Patient { mysqlPatientId: line[0], patDob: line[8] })

Upvotes: 2

Related Questions