问题
I'm trying to send this cypher script via REST:
{"statements":[{"statement":"LOAD CSV WITH HEADERS FROM \"http://localhost:9000/api/csv/Countries/csv\" as csvLine
MERGE (c:Country { Code: csvLine.Code })
RETURN c","resultDataContents":["row"],"includeStats":true}]}
But I am getting back:
{"results":[],"errors":[]}
If I the same embedded query in the Neo4J browser it works fine. The following works fine:
{"statements":[{"statement":"CREATE n RETURN n","resultDataContents":["row"],"includeStats":true}]}
I get back:
{"results":[{"columns":["n"],"data":[{"row":[{}]}],"stats":{"contains_updates":true,"nodes_created":1,"nodes_deleted":0,"properties_set":0,"relationships_created":0,"relationship_deleted":0,"labels_added":0,"labels_removed":0,"indexes_added":0,"indexes_removed":0,"constraints_added":0,"constraints_removed":0}}],"errors":[]}
Anyone have any idea what I am doing wrong? Why would I get the empty errors if it's not working?
回答1:
Change the resultDataContents
value from ["row"]
to ["row", "graph"]
if you want to retrieve back a graph result (nodes and links).
Your updated JSON payload should look like this:
{"statements":[{"statement":"LOAD CSV WITH HEADERS FROM \"http://localhost:9000/api/csv/Countries/csv\" as csvLine
MERGE (c:Country { Code: csvLine.Code })
RETURN c","resultDataContents":["row", "graph"],"includeStats":true}]}
Or you can return back properties, and receive a dataset with columns and rows.
{"statements":[{"statement":"LOAD CSV WITH HEADERS FROM \"http://localhost:9000/api/csv/Countries/csv\" as csvLine
MERGE (c:Country { Code: csvLine.Code })
RETURN c.Code","resultDataContents":["row"],"includeStats":true}]}
The reason no results were returned in your query is because you requested a property of a node in resultDataContents
as the return result but returned a node RETURN c
. When you specify that you want a row/column result back, you must return attributes and not nodes in your RETURN
statement.
回答2:
While I clearly had some issues matching the RETURN portion of my query with the format REST was expecting the results in, the real problem was that the statements in the JSON package cannot go on multiple lines. Which explains all the symptoms I was having. THanks for your help, Kenny! :)
来源:https://stackoverflow.com/questions/25901283/sending-cypher-script-with-load-csv-via-rest-isnt-working-for-me