27

I would like to predefine some graph data for neo4j and be able to load it, maybe via a console tool. I'd like it to be precisely the same as MySQL CLI and .sql files. Does anyone know if there exists a file format like .neo or .neo4j? I couldn't find such thing in the docs...

ducin
  • 25,621
  • 41
  • 157
  • 256

3 Answers3

27

We usually do .cql or .cypher for script files. You can pipe it to the shell to run it, like so:

./neo4j-shell -c < MY_FILE.cypher

Michael Hunger was doing some great work on this feature, also, just recently. He got performance up and noise down from the console. I hope it gets into 1.9 release.

toraritte
  • 6,300
  • 3
  • 46
  • 67
Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
11

From https://groups.google.com/forum/#!topic/opencypher/PO5EnspBLs0

1:

"Sorry for the late reply, but we just wanted to inform you that the official recommendation is to use .cypher. We'll be formalising this in the style guide soon."

2:

"In training run by Neo4j, we've historically used .cyp. I believe the preference is to use .cypher, and .cyp when an extension of 3 chars is required."

3:

"Note: '.cql' is already used for Cassandra - https://cassandra.apache.org/doc/cql/CQL.html"

From the above extracts:
1st preference is .cypher
2nd preference is .cyp (1st 3 characters of cypher)
Don't use .cql

More:

If you need a color coding in notepad++, download the xml given at https://gist.github.com/nicolewhite/b0344ea475852c8c9571 , import it via menu Language > User Defined Language > Import > Restart the Notepad++, open a file with .cypher that has some cyper query language)

Sample cypher is below:

MATCH (:Person {name: "Ann"})        -[:FB_FRIENDS]->    Create (:Person {name: "Dan"})

Hope that helps someone.

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
6

Using neo4j-client as the CLI for Neo4j allows for easy evaluation of scripts. There are several ways to work with a script containing multiple cypher commands:

  1. You can pipe the script in via standard input, e.g.:

    neo4j-client -u neo4j -P localhost < my_script.cyp
    
  2. You can use the command line option --source or -i, e.g.:

    neo4j-client -u neo4j -P -i my_script.cyp localhost
    
  3. You can start an interactive shell, and then source the script:

    $ neo4j-client localhost
    Username: neo4j
    Password: *****
    neo4j-client 1.2.1.
    Enter `:help` for usage hints.
    Connected to 'neo4j://neo4j@localhost:7687'
    neo4j>
    neo4j> :source my_script.cyp
    

The extension .cyp is most commonly used for scripts.

Chris Leishman
  • 1,777
  • 13
  • 19