How to execute Cypher in a file?

2019-02-16 11:33发布

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.

标签: neo4j cypher
6条回答
啃猪蹄的小仙女
2楼-- · 2019-02-16 11:46

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
查看更多
我只想做你的唯一
3楼-- · 2019-02-16 11:47

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.

查看更多
可以哭但决不认输i
4楼-- · 2019-02-16 12:01

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.

查看更多
混吃等死
5楼-- · 2019-02-16 12:03
$ neo4j-shell -file query.cql

or using cypher-shell

$ cat query.cql | cypher-shell
查看更多
Bombasti
6楼-- · 2019-02-16 12:04

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 .

查看更多
别忘想泡老子
7楼-- · 2019-02-16 12:04

./bin/neo4j-shell -path ../data/databases/ -c < commands.cql

on Neo4j 3.2.1

查看更多
登录 后发表回答