1

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?

smartcaveman
  • 41,281
  • 29
  • 127
  • 212
Daniel Corbett
  • 255
  • 2
  • 10
  • This was edited to remove "graph" as one of the values for resultDataContents, as was suggested in the first answer, then to remove the property for c as well as to provide an example of a query that works. No other changes were made to the code besides changing the query loaded from an external file ( and placed into the same surrounding JSON ) – Daniel Corbett Sep 18 '14 at 14:01
  • I updated my answer. It's fine if you want to return a property, as in `c.Code`. You've changed it to `c` in your question. – Kenny Bastani Sep 18 '14 at 14:39

2 Answers2

0

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.

Kenny Bastani
  • 3,268
  • 15
  • 20
  • This doesn't do the load, so why doesn't it produce an error? The meaning of the various arguments is not at all clear, including the graph argument. – Daniel Corbett Sep 18 '14 at 10:22
  • The arguments are explained here: http://docs.neo4j.org/chunked/stable/rest-api-transactional.html#rest-api-return-results-in-graph-format As to why no errors are produced, that seems to be an issue. I will report it so that it is fixed in a future release. If this is the answer to the question, please mark it as answered. – Kenny Bastani Sep 18 '14 at 11:19
  • Unfortunately, that error had nothing to do with whatever is wrong. The symptoms didn't change. – Daniel Corbett Sep 18 '14 at 13:45
  • It really doesn't matter much what I put in the query, or the other parameters. If I put something like: "LOAD CSV WITH HEADERS FROM 'C:\\countries.csvxxx' as csvLine MERGE (c:Country { Code: csvLine.Code })" without any return or resultDataContents specified it gives me the same result. If I make an error in the LOAD CSV syntax, then I get an error. If the CSV LOAD syntax is correct, then it simply acts like it worked, without invoking the load csv. – Daniel Corbett Sep 18 '14 at 17:17
0

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! :)

Daniel Corbett
  • 255
  • 2
  • 10