Skip to content

Gremlin-Console

Gremlin-Console is an interactive client developed by TinkerPop. Users can use this client to perform various operations on Graph. There are two main usage modes:

  • Stand-alone offline mode
  • Client/Server mode

Note: Gremlin-Console is only for users to quickly get started and experience, it is not recommended for use in production environments.

1 Stand-alone offline mode

Since the lib directory already contains the HugeCore jar package, and HugeGraph-Server has been registered in the Console as a plug-in, the users can write a groovy script directly to call the code of HugeGraph-Core, and then hand it over to the parsing engine in Gremlin-Console for execution. As a result, the users can operate the graph without starting the Server.

Here is an example, first modify the hugegraph.properties configuration to use the Memory backend (using other backends may encounter some initialization issues):

1backend=memory
2serializer=text

Then enter the following command:

 1> ./bin/gremlin-console.sh -- -i scripts/example.groovy
 2
 3         \,,,/
 4         (o o)
 5-----oOOo-(3)-oOOo-----
 6plugin activated: HugeGraph
 7plugin activated: tinkerpop.server
 8plugin activated: tinkerpop.utilities
 9plugin activated: tinkerpop.tinkergraph
10main dict load finished, time elapsed 644 ms
11model load finished, time elapsed 35 ms.
12>>>> query all vertices: size=6
13>>>> query all edges: size=6
14gremlin> 

The -- here will be parsed by getopts as the last option, allowing the subsequent options to be passed to Gremlin-Console for processing. -i represents Execute the specified script and leave the console open on completion. For more options, you can refer to the source code of Gremlin-Console.

example.groovy is an example script under the scripts directory. This script inserts some data and queries the number of vertices and edges in the graph at the end.

You can continue to enter Gremlin statements to operate on the graph:

 1gremlin> g.V()
 2==>v[2:lop]
 3==>v[1:josh]
 4==>v[1:marko]
 5==>v[1:peter]
 6==>v[1:vadas]
 7==>v[2:ripple]
 8gremlin> g.E()
 9==>e[S1:josh>2>>S2:lop][1:josh-created->2:lop]
10==>e[S1:josh>2>>S2:ripple][1:josh-created->2:ripple]
11==>e[S1:marko>1>>S1:josh][1:marko-knows->1:josh]
12==>e[S1:marko>1>>S1:vadas][1:marko-knows->1:vadas]
13==>e[S1:marko>2>>S2:lop][1:marko-created->2:lop]
14==>e[S1:peter>2>>S2:lop][1:peter-created->2:lop]
15gremlin> 

For more Gremlin statements, please refer to Tinkerpop Official Website

2 Client/Server mode

Gremlin Console connects to HugeGraph Server through WebSocket. Use the Console and conf/remote.yaml bundled with the same Server version. Keep the serializer settings from that file; change only the address and, if authentication is enabled, credentials. Older configuration files may reference serializer classes that no longer exist.

  1. Prepare the connection configuration and start Server.

    Check the host and port in conf/gremlin-server.yaml. The default WsAndHttpChannelizer handles both WebSocket and HTTP requests; it does not need to be changed. In conf/remote.yaml, hosts must contain the Server address reachable from the Console, and port must match the Gremlin port (default 8182, not the REST port 8080). Start Server following the quick start.

    The current master configuration uses GraphBinary V1 with HugeGraph’s type registry:

    1hosts: [localhost]
    2port: 8182
    3serializer:
    4  className: org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV1
    5  config:
    6    serializeResultToString: false
    7    builder: org.apache.hugegraph.io.HugeGraphTypeSerializerRegistryBuilder
    8    ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry]

    If Server requires authentication, add your actual credentials to the same file:

    1username: admin
    2password: "replace-with-your-password"

    The bundled remote-objects.yaml and gremlin-driver-settings.yaml use the same serializer settings. Keep them aligned if you use them.

  2. Start Console from the Server distribution directory and create a client with a traversal alias.

    1./bin/gremlin-console.sh

    Server binds the graph hugegraph in graphspace DEFAULT as DEFAULT-hugegraph, and its traversal source as __g_DEFAULT-hugegraph. Because hyphens are invalid in Groovy variable names, use .alias(['g': '__g_DEFAULT-hugegraph']) to map it to g when creating the driver client:

    1import org.apache.tinkerpop.gremlin.driver.Cluster
    2cluster = Cluster.open('conf/remote.yaml')
    3client = cluster.connect().alias(['g': '__g_DEFAULT-hugegraph'])
  3. Submit queries through the client.

    1client.submit('g.V().count()').all().get()[0].object
    2client.submit('g.V().toList().size()').all().get()[0].object

    Both return 6 if the sample graph was preloaded at Server startup (other graphs return their actual vertex count). When submitting scripts via client.submit(), no :> prefix is needed.

  4. Close the client and cluster when finished.

    1client.close()
    2cluster.close()

Alternatively, you can connect using Gremlin Console’s built-in :remote command:

1:remote connect tinkerpop.server conf/remote.yaml
2// Use :> as a prefix when submitting scripts through the Console remote connection.
3:remote close

When connected with :remote, expressions prefixed with :> are sent to the remote Server, while normal expressions execute locally in Console.

For more information, see the TinkerPop Gremlin Console reference.