Starting the Gremlin console

Starting the Gremlin console for an interactive environment.

Gremlin is one of the query languages used to interact with DataStax Graph (DSG). 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 DSG.

Procedure

  • Start the Gremlin console using the dse command and passing the additional command gremlin-console:
    dse gremlin-console
    Note: If running DSG from tarball installation, add install_dir/bin to PATH environmental variable.
             \,,,/
             (o o)
    -----oOOo-(3)-oOOo-----
    plugin activated: tinkerpop.server
    plugin activated: tinkerpop.tinkergraph
    gremlin>
    Two plugins are activated by default, as shown. The Gremlin Server, tinkerpop.server, is started so that commands can be issued to DSG. TinkerGraph, an in-memory graph that is used as an intermediary for some graph operations is started with tinkerpop.tinkergraph. The Gremlin console automatically connects to the remote Gremlin Server.
    Note: The Gremlin console packaged with DSG does not allow plugin installation like the Gremlin console packaged with Apache TinkerPop.
  • Gremlin console help can be displayed with the -h flag:
    dse gremlin-console -h
    Usage: gremlin-console [host[:port]] [options] [...]
                      ARG2 ...>...]...
      -C, --color     Disable use of ANSI colors
      -D, --debug     Enabled debug 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
      -Q, --quiet     Suppress superfluous Console output
      -v, --version   Display the version
      -V, --verbose   Enable verbose Console output
    
    DSE Gremlin Console automatically connects at startup to DSE as configured
    in the conf/remote.yaml file. The host and port of this configuration can be
    overridden from the command line using the optional host and port arguments.
    Tip: 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:
    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:
    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:
    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
      :grab       (:g  ) Add a dependency to the shell environment
      :register   (:rc ) Register a new command with the shell
      :doc        (:D  ) Open 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
      :bytecode   (:bc ) Gremlin bytecode helper commands
    
    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.

    Note: :install and :plugin should not be used with DSE Graph. These commands will result in gremlin console errors.
  • Once a graph exists, a graph traversal g is configured that will allow graph traversals to be executed. Graph traversals are used to query the graph data and return results. The graph traversal can be bound to either the standard OLTP engine or the OLAP engine. In order to execute any schemas or other queries in the Gremlin console, a graph traversal must be executed first. Configure a graph traversal g to use a graph, in this example, called food_qs.
    :remote config alias g food_qs.g
    
    ==>g=food_qs.g
    Important: As with all queries in Graph, if you are using Gremlin console, alias the graph traversal g to a graph with :remote config alias g food_qs.g before running any commands.