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?

4

2 回答 2

3

试试这个 gremlin 查询:

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

您不需要手动删除边,因为如果删除了一个顶点,与之关联的所有边都将被自动删除。并删除您需要使用迭代查询的所有顶点。

清除图表后,您将不再需要新的 KeySpace。然后你可以使用:

gremlin> g.createKeyIndex("my_key",Vertex.class)
于 2013-07-08T05:45:37.583 回答
3

将 Titan 指向一个新的 Cassandra 数据存储并在插入具有该属性的任何元素之前创建索引。

gremlin> g.createKeyIndex("my_key",Vertex.class)
==>null
于 2013-06-15T15:28:31.650 回答