First, I follow these steps to create a graph in JanusGraph.
conf/janusgraph-cassandra-configurationgraph.properties
index.search.backend = elasticsearch
index.search.hostname = 127.0.0.1
index.search.elasticsearch.transport-scheme = http
change "ConfigurationManagementGraph: conf/janusgraph-cql-configurationgraph.properties" in gremlin-server-configuration.yaml to "ConfigurationManagementGraph: conf/janusgraph-cassandra-configurationgraph.properties"
change conf/gremlin-server/gremlin-server.yaml to conf/gremlin-server/gremlin-server.yaml.orig
change conf/gremlin-server/gremlin-server-configuration.yaml to conf/gremlin-server/gremlin-server.yaml
run bin/janusgraph.sh start
run bin/gremlin.sh
run
:remote connect tinkerpop.server conf/remote.yaml session
:remote console
map = new HashMap<String, Object>();
map.put("storage.backend", "cassandrathrift");
map.put("storage.hostname", "127.0.0.1");
map.put("graph.graphname", "KG");
map.put("index.search.backend", "elasticsearch");
map.put("index.search.hostname", "127.0.0.1");
map.put("index.search.elasticsearch.transport-scheme", "http");
ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
graph=ConfiguredGraphFactory.open("KG");
g=graph.traversal();
ConfiguredGraphFactory.getGraphNames()
turn off janusgraph, run bin/janusgraph.sh stop
make a copy of conf/janusgraph-cassandra-es.properties to conf/KG.properties
add the following two lines to the top of conf/KG.properties
gremlin.graph=org.janusgraph.core.ConfiguredGraphFactory
graph.graphname=KG
KG: conf/KG.properties
add "scripts/empty-sample.groovy" to "org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin:"
open script/empty-sample.groovy, change the last line to the following:
globals << [g : KG.traversal()]
Second, I run bin/gremlin.sh
:remote connect tinkerpop.server conf/remote.yaml session
:remote console
graph=ConfiguredGraphFactory.open("KG");
g=graph.traversal();
g.addV('user').property('name', 'Robert')
g.V()
==>v[4120]
Third, however, when I exit from gremlin console, and get into the gremlin console again like above, when I try to query g.V(), I see nothing returned.
Any idea why this is happening? Thank you very much!
I think it's because you failed to close the transaction with g.tx().commit()
after you add your vertex.
Note that Gremlin Server does manage sessions and calls commit()
for you, but by doing:
:remote connect tinkerpop.server conf/remote.yaml session
you've explicitly opened a connection that does not manage sessions. If you want a session that is managed and auto-commits on every request then you need to do:
:remote connect tinkerpop.server conf/remote.yaml session-managed
http://tinkerpop.apache.org/docs/current/reference/#console-sessions