Skip to content

Instantly share code, notes, and snippets.

@ayosec
Last active October 15, 2015 05:14
Show Gist options
  • Save ayosec/0ca96bc4b7e2e296dfa8 to your computer and use it in GitHub Desktop.
Save ayosec/0ca96bc4b7e2e296dfa8 to your computer and use it in GitHub Desktop.
Neo4j Shell client

Neo4j Shell Client

Launch Neo4j shell commands through the HTTP REST interface.

You have to set the environment variable GRAPHENEDB_URL with the URL of your Neo4j database. For example:

$ export GRAPHENEDB_URL="http://MyUser:[email protected]:12345"

Now, you can launch commands:

$ ./neo4j-shell help
Available commands: alias begin cd commit create cypher dbinfo drop dump env explain export gsh help index jsh load ls man match merge mknode mkrel mv optional paths planner profile pwd return rm rmnode rmrel rollback schema set start trav unwind using with
Use man <command> for info about each command.



$ ./neo4j-shell "man schema"

Accesses db schema. Usage: schema <action> <options...>
Listing indexes
  schema ls
  schema ls -l :Person
Sample indexes all indexes
  schema sample -a
Sample a specific index
  schema sample -l :Person -p name
Force a sampling of a specific index
  schema sample -f -l :Person -p name
Awaiting indexes to come online
  schema await -l Person -p name.

  -a	 Used together with schema sample to indicate that all indexes should be sampled.
  -f	 Used together with schema sample to force indexes to be sampled.
  -l	 Specifies which label selected operation is about.
  -p	 Specifies which property selected operation is about.
  -v	 Verbose output of failure descriptions etc.



$ ./neo4j-shell 'match (n) where n.a < 2000 return n;'
+-----------------+
| n               |
+-----------------+
| Node[0]{a:1000} |
| Node[2]{a:500}  |
+-----------------+
2 rows
63 ms



$ ./neo4j-shell dump
begin
create (_0 {`a`:1000})
create (_1 {`a`:3300})
create (_2 {`a`:500})
;
#!/usr/bin/env ruby
if ARGV.size != 1
STDERR.puts "Usage #$0 'shell command'"
exit 1
end
require "net/http"
require "json"
URL = URI(ENV["GRAPHENEDB_URL"] || raise("Missing GRAPHENEDB_URL variable"))
Net::HTTP.start(URL.hostname, URL.port, use_ssl: URL.scheme == "https") do |http|
response = http.request(Net::HTTP::Post.new("/db/manage/server/console").tap do |request|
request.content_type = "application/json"
request.basic_auth URL.user, URL.password
request.body = { command: ARGV.first, engine: "shell" }.to_json
end)
case response
when Net::HTTPOK
print JSON.parse(response.body)[0]
else
STDERR.puts "Failed: #{response.class.name}\n#{response.body}"
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment