Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute Cypher in a file?

Tags:

neo4j

cypher

I am working on windows. I have created a text file of Cypher query using notepad. How can I run the query in the file using Neo4jShell or Neo4j web interface console.

like image 797
Dinesh Avatar asked Jul 04 '13 05:07

Dinesh


People also ask

How do you run a cypher script?

A command line shell where you can execute Cypher against an instance of Neo4j. By default the shell is interactive but you can use it for scripting by passing cypher directly on the command line or by piping a file with cypher statements (requires Powershell on Windows).

How do I save a cypher file?

Use the keyboard shortcut Command + Option + J (Mac) or Control + Shift + J (Windows/Linux).

Can you run Cypher statements on the system database?

You can use cypher-shell to populate the default database by sending pre-written Cypher statements to the database to execute. Here we have download a file named movies. cypher that contains the Cypher statements to create the Movie graph.

How do you exit a cypher shell?

Running Cypher Shell within the Neo4j distribution Note that Cypher queries must end with a semicolon.


2 Answers

On Debian/Ubuntu or any *nix installations, use the following from terminal:

$ neo4j-shell -c < path-to-cypher-query-file.cql

Note that each cypher query in the file must end in a semicolon and must be separated by a blank line from the other query. Also, the .cql ending (file format) is not mandatory.

like image 75
kmario23 Avatar answered Oct 08 '22 16:10

kmario23


Just add -file as a parameter when starting the console.

On windows, it would look like this :

Neo4jShell.bat -file path/to/cql/file 

Or you could also print the result into a new file

Neo4jShell.bat -file path/to/cql/file > path/to/output/file

I'm also sure there is a way to do it from within the shell and not at startup, as it was once demonstrated to me by Stefan Armbruster but for the love of god, I can't remember how he did it. But this approach works as well.

like image 35
Pieter-Jan Avatar answered Oct 08 '22 16:10

Pieter-Jan