简体   繁体   中英

Neo4j CSV Import Type Error

I'm trying to import a CSV file into Neo4j (Community Edition V 2.3.2). The CSV is structured like this:

id,title,value,updated
123456,"title 1",10,20160407
123457,"title 2",11,20160405

The CSV path is set within the Neo4j properties file.

When I use the following import statement

LOAD CSV WITH HEADERS FROM   
'file:///test.csv' AS line
CREATE (:Title_Node { title: line[1], identifier: toInt(line[0]), value: line[3]})

I receive the following error message:

WARNING: Expected 1 to be a java.lang.String, but it was a java.lang.Long

When I just query the test.csv file with

LOAD CSV WITH HEADERS FROM 'file:///test.csv'
AS line
RETURN line.title, line.id, line.value;

Cypher can access the data without any problem.

+------------------------------------+
| line.title | line.id  | line.value |
+------------------------------------+
| "title 1"  | "123456" | "10"       |
| "title 2"  | "123457" | "11"       |
+------------------------------------+

The effect occurs in the browser as well as in the shell.

I found the following question at Having `Neo.ClientError.Statement.InvalidType` in Neo4j and tried the hints mentioned in the Neo4j Link posted in this answer, but with little success. The CSV file itself seems to be ok by structure (UTF8, no hidden entries etc.).

Every help in solving this is greatly appreciated.

Best

Krid

You're supplying the fields for the line header, so use them in the import -

LOAD CSV WITH HEADERS FROM   
'file:///test.csv' AS line
CREATE (:Title_Node { title: line.title, identifier: line.id, value: line.value})

This is a classic example of an error message which is entirely correct, but not very helpful!

You can supply literals to line indexes if you prefer-

LOAD CSV WITH HEADERS FROM   
'file:///test.csv' AS line
CREATE (:Title_Node { title: line['title'], identifier: line['id'], value: line['value']})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM