图表未保存

Rob*_*ang 3 gremlin tinkerpop gremlin-server janusgraph

首先,我按照以下步骤在 JanusGraph 中创建一个图形。

  • 将以下内容添加到 conf/janusgraph-cassandra-configurationgraph.properties
index.search.backend = elasticsearch
index.search.hostname = 127.0.0.1
index.search.elasticsearch.transport-scheme = http
Run Code Online (Sandbox Code Playgroud)
  • 将 gremlin-server-configuration.yaml 中的“ConfigurationManagementGraph:conf/janusgraph-cql-configurationgraph.properties”更改为“ConfigurationManagementGraph:conf/janusgraph-cassandra-configurationgraph.properties”

  • 将 conf/gremlin-server/gremlin-server.yaml 更改为 conf/gremlin-server/gremlin-server.yaml.orig

  • 将 conf/gremlin-server/gremlin-server-configuration.yaml 更改为 conf/gremlin-server/gremlin-server.yaml

  • 运行 bin/janusgraph.sh start

  • 运行 bin/gremlin.sh

: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()
Run Code Online (Sandbox Code Playgroud)
  • 关闭 janusgraph,运行 bin/janusgraph.sh 停止

  • 将 conf/janusgraph-cassandra-es.properties 复制到 conf/KG.properties

  • 在 conf/KG.properties 顶部添加以下两行

gremlin.graph=org.janusgraph.core.ConfiguredGraphFactory
graph.graphname=KG
Run Code Online (Sandbox Code Playgroud)
  • 打开 conf/gremlin-server/gremlin-server.yaml,并将以下行添加到图形中:
KG: conf/KG.properties
Run Code Online (Sandbox Code Playgroud)
  • 将“scripts/empty-sample.groovy”添加到“org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin:”

  • 打开 script/empty-sample.groovy,将最后一行修改为:

globals << [g : KG.traversal()]
Run Code Online (Sandbox Code Playgroud)
  • 通过运行 bin/janusgraph.sh start 再次启动 janusgraph

其次,我运行 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()
Run Code Online (Sandbox Code Playgroud)
  • 我可以看到它返回一个顶点 ==>v[4120]

第三,然而,当我从 gremlin 控制台退出,并像上面一样再次进入 gremlin 控制台时,当我尝试查询 gV() 时,我看不到任何返回。

知道为什么会这样吗?非常感谢!

ste*_*tte 5

我认为这是因为您g.tx().commit()在添加顶点后未能关闭交易。

请注意,Gremlin Server 确实commit()为您管理会话和调用,但通过执行以下操作:

:remote connect tinkerpop.server conf/remote.yaml session
Run Code Online (Sandbox Code Playgroud)

您已经明确打开了一个不管理会话的连接。如果您想要一个受管理的会话并在每个请求上自动提交,那么您需要执行以下操作:

:remote connect tinkerpop.server conf/remote.yaml session-managed
Run Code Online (Sandbox Code Playgroud)

http://tinkerpop.apache.org/docs/current/reference/#console-sessions