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.
With Neo4j web interface I just do copy&paste.
On the console I sometimes use curl to talk to Neo4j's REST interface. That allows me to use the same queries (with references to separate parameters) that I have in my application. You have to wrap the query in your file into a json object for that.
data.json:
{
"query":"match (u:User) where u.username={username} return u",
"params":{"username":"trenkerbe"}
}
command:
curl -i -X POST -H "Content-Type: application/json" -d @data.json http://localhost:7474/db/data/cypher
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.
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.
The neo4jShell.bat file has been removed since this question was asked. The new approach to execute cypher files is to use the web application called LazyWebCypher .
./bin/neo4j-shell -path ../data/databases/ -c < commands.cql
on Neo4j 3.2.1
$ neo4j-shell -file query.cql
or using cypher-shell
$ cat query.cql | cypher-shell