How to export a csv file of a large set of results using cypher in Neo4j in a browser?

I am using Neo4j in my browser on Ubuntu. I have received over 1 million nodes and I want to export them to a csv file.

When the size of the return data is small, like "match n return n limit 3", you can use the large "load csv" button. But when it comes to a big result, such as more than 1000, the shell simply says β€œToo many results (more than 1000 lines),” and the button does not appear.

How to export csv files for a large set of results?

+6
source share
6 answers

You can also use my shell extensions to export cypher results to CSV.

See here: https://github.com/jexp/neo4j-shell-tools#cypher-import

Just specify the -o output.csv file for the import-cypher command.

+4
source

We followed the approach described below. This works very well for us. data is correctly formatted in csv format.

 https://github.com/jexp/neo4j-shell-tools#cypher-import import-cypher command from neo4J shell. neo4j-sh (?)$ import-cypher -o test.csv MATCH (m:TDSP) return m.name 
+2
source

Well, I just used the linux shell to do all the work.

neo4j-shell -file query.cql | sed 's/|/;/g' > myfile.csv

In my case, I also had to convert from UTF-8 to ISO-8859-1, so I typed:

neo4j-shell -file query.cql | sed 's/|/;/g' | iconv -f UTF-8 -t ISO-8859-1 -o myfile.csv

PS: sed replaces: 's / | /; / g' means replaces (s) with all "|" on the ";" even if for each row (g) more than 1)

Hope this helps. Relations

+1
source

I know this is an old post, but maybe this will help someone else. For those using the Symfony Framework, you can make a fairly simple controller to export the Neo4j Cypher Queries to CSV. To use raw cypher requests, Grapharare NEO4J PHP OGM ( https://github.com/graphaware/neo4j-php-ogm ) is used. I assume this can also be easily implemented without using Symfony using simple PHP.

Just create a form (with a branch if you want):

  <form action="{{ path('admin_exportquery') }}" method="get"> Cypher:<br> <textarea name="query"></textarea><br> <input type="submit" value="Submit"> </form> 

Then configure the route "admin_exportquery" to point to the controller. And add a controller to handle the export:

 public function exportQueryAction(Request $request) { $query = $request->query->get('query'); $em = $this->get('neo4j.graph_manager')->getClient(); $response = new StreamedResponse(function() use($em,$query) { $result = $em->getDatabaseDriver()->run($query); $handle = fopen('php://output', 'w'); fputs( $handle, "\xEF\xBB\xBF" ); $header = $result->getRecords()[0]->keys(); fputcsv($handle, $header); foreach($result->getRecords() as $r){ fputcsv($handle, $r->values()); } fclose($handle); }); $response->headers->set('Content-Type', 'application/force-download'); $response->headers->set('Cache-Control', 'no-store, no-cache'); $response->headers->set('Content-Disposition','attachment; filename="export.csv"'); return $response; } 

This allows you to download CSV with utf-8 characters directly from your browser and gives you all the freedom of Cypher.

IMPORTANT: this does not have a request to check what it is, and it is a very good idea to set up an appropriate security check or request before use :)

0
source

Cypher-shell:

 https://neo4j.com/docs/operations-manual/current/tools/cypher-shell/ 

which is included in recent versions of neo4j, is easy:

 cat query.cql | cypher-shell > answer.csv 
0
source

The limit of 1000 is due to the MaxRows browser setting. You can change it, for example. 10000 and, thus, will be able to download these 10000 in one go through the csv download / export button described in the original message. On my laptop, the limit for the download button is somewhere between 10,000 and 20,000. By setting the MaxRows limit to 50,000 or 300,000, I was able to get the data on the screen after waiting. Manual selection, copying and pasting work. However, to do anything else but close the browser after each request is impossible, as the browser becomes very slow.

0
source

Source: https://habr.com/ru/post/973552/


All Articles