Create an index on a vertex property that already exists in Titan (Cassandra)?
Asked Answered
E

2

6

I am using Titan Server (Cassandra) v 0.3.1. I'd like to create an index on a vertex key/property that I have already started to use. However, in their documentation, Titan explains that:

To index vertices by key, the respective key index must be created before the key is first used in a vertex property.

If I try to create an index on a field that already exists, I see an error as expected:

gremlin> g.createKeyIndex("my_key",Vertex.class)
Cannot add an index to an already existing property key: my_key

However, even if I try to clear out the graph by removing all vertices & edges, I see the same error:

gremlin> g.E.remove()
==>null
gremlin> g.V.remove()
==>null
gremlin> g.createKeyIndex("my_key",Vertex.class)
Cannot add an index to an already existing property key: my_key

So it seems that my_key persists in the underlying data store even after all of the graph elements are removed. This is consistent with the docs (even though elements have been deleted the property has already been 'first used'), but seemed worth a shot.

My next step is going to be to re-create a new Cassandra data store altogether, but I'm wondering if there is a better option.

What is the easiest way to create an index on a field that has already been used in Titan?

Evangelist answered 15/6, 2013 at 15:28 Comment(0)
E
3

Point Titan to a new Cassandra data store and create the index before inserting any elements with that property.

gremlin> g.createKeyIndex("my_key",Vertex.class)
==>null
Evangelist answered 15/6, 2013 at 15:28 Comment(0)
E
3

Try this gremlin query:

gremlin> g.V.each{g.removeVertex(it)}

You don't need to remove Edges manually, because if a vertex is removed, all the edges associated with it will be removed automatically. And to remove all the vertices you need to use a Iterative query.

Once the graph is cleared, you will not need a new KeySpace. You can then use:

gremlin> g.createKeyIndex("my_key",Vertex.class)
Estevez answered 8/7, 2013 at 5:45 Comment(3)
Thanks for your answer-- unfortunately, that doesn't seem to do it on this end. I think g.V.each{g.removeVertex(it)} is roughly equivalent to g.V.remove() (see related). When I tried your alternate method for removing vertices, Titan had the same complaint: Cannot add an index to an already existing property key: my_key.Evangelist
Did you commit the transaction after removing ?Estevez
I did, no difference: gremlin> g.V.each{g.removeVertex(it)}; g.commit(); g.createKeyIndex("my_key", Vertex.class); Cannot add an index to an already existing property key: my_keyEvangelist

© 2022 - 2024 — McMap. All rights reserved.