Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use gremlin-console to remotely create and access variables?

I remotely connect to a gremlin server using gremlin-console(which is janusgraph), but when I create a variable and access it, it doesn't work. My ultimate goal is to use gremlin-console to create index...

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - 
[localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> a = "b"
==>b
gremlin> a
No such property: a for class: Script3
Type ':help' or ':h' for help.
like image 526
Gao Avatar asked Aug 18 '17 07:08

Gao


People also ask

How do you add a vertex in Gremlin?

3.1 Adding a Vertex In Gremlin nodes are referred to as “Vertexes”. To add a node/vertex to the graph, you simply use the command addV() on your graph traversal source. For consistency, most people use “g” as their default graph traversal source. To append properties to your your vertex, you add a series of “.

How do I clear my Gremlin console?

On Linux and on Mac OS X typing CTRL-L will clear the screen.


2 Answers

You can't use variables like this for subsequent requests, because the console is by default sessionless. So every request is executed in its own transaction and no state is shared between two different requests.

However you can configure the console to use a session by simply appending the session keyword to the connect argument:

gremlin> :remote connect tinkerpop.server conf/remote.yaml session
==>Configured localhost/127.0.0.1:8182-[15dc7030-0e5b-4b4b-a997-9d2cf519ebb2]
gremlin> :> x = 1
==>1
gremlin> :> y = 2
==>2
gremlin> :> x + y
==>3

I copied this example from the TinkerPop documentation for this topic.

like image 139
Florian Hockmann Avatar answered Sep 22 '22 18:09

Florian Hockmann


Download janusdb and launch the gremlin console by running

/bin/gremlin.sh

Construct the janus graph using the following command:

gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cassandra-solr.properties')

Get your graph traversal source by running:

gremlin> g = graph.traversal()

Now you are connected directly to the database with the full control. You can store the return values and use it in the next queries.

like image 40
Chandran Anjur Avatar answered Sep 21 '22 18:09

Chandran Anjur