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):
Then enter the following command:
The
--here will be parsed by getopts as the last option, allowing the subsequent options to be passed to Gremlin-Console for processing.-irepresentsExecute 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:
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.
Prepare the connection configuration and start Server.
Check the
hostandportinconf/gremlin-server.yaml. The defaultWsAndHttpChannelizerhandles both WebSocket and HTTP requests; it does not need to be changed. Inconf/remote.yaml,hostsmust contain the Server address reachable from the Console, andportmust match the Gremlin port (default8182, not the REST port8080). Start Server following the quick start.The current master configuration uses GraphBinary V1 with HugeGraph’s type registry:
If Server requires authentication, add your actual credentials to the same file:
The bundled
remote-objects.yamlandgremlin-driver-settings.yamluse the same serializer settings. Keep them aligned if you use them.Start Console from the Server distribution directory and create a client with a traversal alias.
Server binds the graph
hugegraphin graphspaceDEFAULTasDEFAULT-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 togwhen creating the driver client:Submit queries through the client.
Both return
6if the sample graph was preloaded at Server startup (other graphs return their actual vertex count). When submitting scripts viaclient.submit(), no:>prefix is needed.Close the client and cluster when finished.
Alternatively, you can connect using Gremlin Console’s built-in :remote command:
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.