How to execute Cypher in a file?

前端 未结 6 1162
情深已故
情深已故 2021-01-04 01:39

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.

相关标签:
6条回答
  • 2021-01-04 01:53

    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
    
    0 讨论(0)
  • 2021-01-04 01:56

    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.

    0 讨论(0)
  • 2021-01-04 02:00

    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.

    0 讨论(0)
  • 2021-01-04 02:06

    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 .

    0 讨论(0)
  • 2021-01-04 02:07

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

    on Neo4j 3.2.1

    0 讨论(0)
  • 2021-01-04 02:08
    $ neo4j-shell -file query.cql
    

    or using cypher-shell

    $ cat query.cql | cypher-shell
    
    0 讨论(0)
提交回复
热议问题