我刚刚开始在 Cassandra 上使用 Titan。我是 Titan 的新手,也是图形数据库概念的新手。只需按照 github 和 wiki 上的说明进行操作。
Configuration conf = new BaseConfiguration();
conf.setProperty("storage.backend", "cassandra");
conf.setProperty("storage.hostname", "127.0.0.1");
TitanGraph g = TitanFactory.open(conf);
这就是我打开图表的方式。
我知道默认的 key 空间是
titan
.我在默认键空间中创建了一些节点和关系。我对顶点进行索引并查询节点并能够遍历结果。现在我的问题 -
1) 如何设置新的 key 空间?
我尝试使用该属性
conf.setProperty("storage.keyspace ", "newkeyspace");
不幸的是,当我检查 cassandra 键空间时,我只能找到
titan
.没有名为 newkeyspace
的键空间.可能是什么原因?2)我如何坚持已创建的图表?
例如,
g.createKeyIndex("name", Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno.setProperty("type", "node");
Vertex juno1 = g.addVertex(null);
juno1.setProperty("name", "juno");
juno1.setProperty("type", "node1");
这是一个示例图。一旦我发出表单的查询
Iterator<Vertex> junoIterator = g.getVertices("name", "juno")
.iterator();
while (junoIterator.hasNext()) {
Vertex vertex = (Vertex) junoIterator.next();
System.out.println(vertex.getProperty("type"));
}
我的预期结果是
node
node1
一旦我评论以下部分,相同的查询应该可以正常工作 -
/*g.createKeyIndex("name", Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno.setProperty("type", "node");
Vertex juno1 = g.addVertex(null);
juno1.setProperty("name", "juno");
juno1.setProperty("type", "node1");*/
在这里,我相信节点、关系和索引已经建立并保存在某个数据存储中。我是不是信仰错误?
请指教。
最佳答案
我已经弄清楚了这个问题。只是一个 promise 的问题。
单行g.commit();
解决这一切。
关于graph-databases - 在 Titan Cassandra 中使用新的 KeySpaces 并持久化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223196/