Starting the Gremlin console
Gremlin is the query language used to interact with DSE Graph. One method of inputting Gremlin code is to use the Gremlin console. The Gremlin console is a useful interactive environment for directly inputting Gremlin to create graph schema, load data, administer graph, and retrieve traversal results. The Gremlin Console is an interface to the Gremlin Server that can interact with DSE Graph.
-
Start the Gremlin console using the
dse
command and passing the additional commandgremlin-console
:$ bin/dse gremlin-console
$ \,,,/ (o o) -----oOOo-(3)-oOOo----- plugin activated: tinkerpop.server plugin activated: tinkerpop.utilities plugin activated: tinkerpop.tinkergraph gremlin>
Three plugins are activated by default, as shown. The Gremlin Server,
tinkerpop.server
, is started so that commands can be issued to DSE Graph. The utilities plugin,tinkerpop.utilities
, provides various functions, helper methods and imports of external classes that are useful in Gremlin console. TinkerGraph, an in-memory graph that is used as an intermediary for some graph operations is started withtinkerpop.tinkergraph
. The Gremlin console automatically connects to the remote Gremlin Server.The Gremlin console packaged with DataStax Enterprise does not allow plugin installation like the Gremlin console packaged with Apache TinkerPop.
-
Gremlin console help can be displayed with the
-h
flag:$ bin/dse gremlin-console -h
$ usage: gremlin.sh [options] [...] -C, --color Disable use of ANSI colors -D, --debug Enabled debug Console output -Q, --quiet Suppress superfluous Console output -V, --verbose Enable verbose Console output -e, --execute=SCRIPT ARG1 ARG2 ... Execute the specified script (SCRIPT ARG1 ARG2 ...) and close the console on completion -h, --help Display this help message -i, --interactive=SCRIPT ARG1 ARG2 ... Execute the specified script and leave the console open on completion -l Set the logging level of components that use standard logging output independent of the Console -v, --version Display the version
Use
-V
to display all lines when loading a file, to discover which line of code causes an error. -
Run the Gremlin console with the
host:port
option to specify a specific host and port:$ bin/dse gremlin-console 127.0.0.1:8182
Any hostname or IP address will work to specify the
host
. -
Run Gremlin console with the
-e
flag to execute one or more scripts:$ bin/dse gremlin-console -e test1.groovy -e test2.groovy
If the scripts run successfully, the command will return with the prompt after execution. If errors occur, the standard output will show the errors.
-
If you prefer to have Gremlin console open at the script completion, run Gremlin console with the
-i
flag instead of the-e
flag:$ bin/dse gremlin-console -i test1.groovy -i test2.groovy
If the scripts run successfully, the command will return with the Gremlin console prompt after execution. If errors occur, the console will show the errors.
-
Discover all Gremlin console commands with help. Console commands are not Gremlin language commands, but rather commands issued to the Gremlin console for shell functionality. The Gremlin console is based on the Groovy shell.
$ :help
$ For information about Groovy, visit: http://groovy-lang.org Available commands: :help (:h ) Display this help message ? (:? ) Alias to: :help :exit (:x ) Exit the shell :quit (:q ) Alias to: :exit import (:i ) Import a class into the namespace :display (:d ) Display the current buffer :clear (:c ) Clear the buffer and reset the prompt counter. :show (:S ) Show variables, classes or imports :inspect (:n ) Inspect a variable or the last result with the GUI object browser :purge (:p ) Purge variables, classes, imports or preferences :edit (:e ) Edit the current buffer :load (:l ) Load a file or URL into the buffer . (:. ) Alias to: :load :save (:s ) Save the current buffer to a file :record (:r ) Record the current session to a file :history (:H ) Display, manage and recall edit-line history :alias (:a ) Create an alias :register (:rc ) Registers a new command with the shell :doc (:D ) Opens a browser window displaying the doc for the argument :set (:= ) Set (or list) preferences :uninstall (:- ) Uninstall a Maven library and its dependencies from the Gremlin Console :install (:+ ) Install a Maven library and its dependencies into the Gremlin Console :plugin (:pin) Manage plugins for the Console :remote (:rem) Define a remote connection :submit (:> ) Send a Gremlin script to Gremlin Server For help on a specific command type: :help command
The Gremlin Console provides code help via auto-complete functionality, using the
<TAB>
key to trigger a list of possible options.:install
and:plugin
should not be used with DSE Graph. These commands will result in gremlin console errors.