JanusGraph Java无法添加顶点/边

ajs*_*ajs 4 java gremlin janusgraph java-11

我一直在尝试在 docker 中与我的 JanusGraph 设置进行交互。但经过多次尝试我仍然没有成功。

我如何连接到 JG。

    public boolean connect() {
        try {
            graph = traversal().withRemote("path/to/janusgraph-cql-lucene-server.properties");
            return true;
        } catch (Exception e) {
            log.error("Unable to create connection with graph", e);
            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我如何尝试添加顶点。看起来这并没有什么作用。

        GraphTraversal<Vertex, Vertex> yt = graph.addV("link")
                .property("url", "https://www.youtube.com/123")
                .property("page_type", "contact");


        GraphTraversal<Vertex, Vertex> fb = graph.addV("link")
                .property("url", "https://www.facebook.com/456");
        
        graph.tx().commit();
Run Code Online (Sandbox Code Playgroud)
我已经使用 gremlin 控制台添加了一个节点。这是有效的,所以设置不是无效的或类似的东西。当我获取应用程序中的所有节点时,我会得到有效的响应。
System.out.println(graph.V().hasLabel("link").count().next()); //returns 1 (the node I added manually)
Run Code Online (Sandbox Code Playgroud)

我的假设:

  • 设置没问题,因为它可以在 gremlin 控制台中运行
  • 联系
  • 连接一定没问题,因为初始化不会引发异常,并且我们会得到有效的计数响应。

我唯一不确定的是是否缺少我的事务提交。除了我没找到其他的graph.tx().commit();

你能帮助我并告诉我我做错了什么吗?

Had*_*arc 5

GraphTraversal 对象只是一个要执行的“计划”。要使其生效,您需要一个关闭方法,如 next、toList 等,就像您对计数所做的那样。

造成混乱的原因可能是 gremlin 控制台自动按照配置的次数继续进行接下来的遍历。

  • 当然,有关终端步骤的更多信息可以在 https://tinkerpop.apache.org/docs/current/reference/#basic-gremlin 找到 (2认同)