我正在尝试向 JanusGraph 添加顶点和边,但它似乎没有按预期工作。我使用 Cassandra 和 Elasticsearch 作为后端。我可以添加顶点。我使用下面的代码来测试是否添加了顶点和边。
this.graph = JanusGraphFactory.open("conf/janusgraph-cassandra-es.properties");
trv = graph.traversal()
trv.V().count()
//Returns count and runs as expected
trv.E().count()
//Returns 0 even though I added the edges
我使用下面的代码来添加边缘。
tx = this.graph.newTransaction();
Long vertexId = companyMap.get(Integer.parseInt(record.get("ASSIGNEE")));
Vertex assignee = this.traversal.V(vertexId).next();
Vertex patent = this.traversal.V(patentId).next();
patent.addEdge("assigned_to", assignee);
tx.commit();
我根据下面 Jason 的评论更改了代码。现在,每当我想要获取现有顶点然后添加边时,我都会创建新的遍历对象。现在似乎可以正常工作了。
GraphTraversalSource trv = this.graph.traversal();
Long vertexId = companyMap.get(Integer.parseInt(record.get("ASSIGNEE")));
Vertex assignee = this.traversal.V(vertexId).next();
Vertex patent = this.traversal.V(patentId).next();
patent.addEdge("assigned_to", assignee);
trv.tx().commit();
最佳答案
使用最新的janusgraph 0.3.x版本,其中包括不同后端的使用示例
关于java - JanusGraph 添加边缘似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51005149/