Question

I have just started using Titan over Cassandra. I am new to Titan and also new to the the Graph Database Concept. Just followed the instructions on github and wiki.

Configuration conf = new BaseConfiguration();
conf.setProperty("storage.backend", "cassandra");
conf.setProperty("storage.hostname", "127.0.0.1");
TitanGraph g = TitanFactory.open(conf);

This is how I opened the graph.

I understand that the default key space is titan. I created some nodes and relations in the default key space. I did Indexing on the vertex and queried the nodes and were able to iterate through the results.

Now my questions -

1) How do I set a new Key Space ?

I tried using the property

conf.setProperty("storage.keyspace ", "newkeyspace");

Unfortunately, when I checked the cassandra keyspaces, I could only find titan. There was no keyspace by the name newkeyspace. What could be the reason?

2) How do I persist a graph have been created?

for example,

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

This is one sample graph. Once I issue a query of the form

Iterator<Vertex> junoIterator = g.getVertices("name", "juno")
                .iterator();
        while (junoIterator.hasNext()) {
            Vertex vertex = (Vertex) junoIterator.next();
            System.out.println(vertex.getProperty("type"));
        }

My expected result is

node 
node1

The same query should work fine once I comment the following segment -

    /*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");*/

Here, what I believe is that the nodes, relations and index already have been built and is persisted in some datastore. Am I of the wrong belief?

Please advice.

Was it helpful?

Solution

I have figured out the issue. Was just a matter of commit.

A single line g.commit(); solves it all.

OTHER TIPS

To create a new Titan Table(Keyspace in cassandra) in please use the property :

set("storage.cassandra.keyspace","TitanTest")

the whole command wud be like :

graph = TitanFactory.build(). set("storage.backend","cassandra"). set("storage.hostname","127.0.0.1").set("index.search.backend","elasticsearch").set("storage.cassandra.astyanax.cluster-name","Test Cluster").set("storage.cassandra.keyspace","TitanTest").set("cache.db-cache","true").open();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top