JanusGraph Java无法添加顶点/边

发布于 2025-01-12 00:32:58 字数 1352 浏览 0 评论 0原文

我一直在尝试在 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;
        }
    }

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

        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();

I've added a node with the gremlin console. This works, so the setup is not invalid or something like that. And when I fetch all nodes I in my application get a valid response.
System.out.println(graph.V().hasLabel("link").count().next()); //returns 1 (the node I added manually)

我的假设:

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

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

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

I've been trying to create interact with my JanusGraph setup in docker. But after many tries I still don't succeed.

How I connect to 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;
        }
    }

How I try to add a vertex. It looks like this doesn't do anything.

        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();

I've added a node with the gremlin console. This works, so the setup is not invalid or something like that. And when I fetch all nodes I in my application get a valid response.

System.out.println(graph.V().hasLabel("link").count().next()); //returns 1 (the node I added manually)

My assumptions:

  • Setup is alright because it works in the gremlin console
  • connection
  • connection must be alright because the initialization doesn't throw an exception and we get a valid count response.

The only thing I'm not sure about is if there's a transaction commit that I am missing. I didn't find any other than graph.tx().commit();

Could you please help me and tell me what I am doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗲 2025-01-19 00:32:58

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

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

The GraphTraversal object is only a "plan" to be carried out. To have it take effect, you need a closing method like next, toList, etc., like you did for the count.

The confusion probably arose from the fact that the gremlin console automatically keeps nexting the traversal a configured number of times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文