How to set a vertex's Index myself in Titan Graph Database

96 views Asked by At

The thing is that whenever I add a vertex with "addVertex()" command, the index of the vertex is chosen randomly like V[0] and the second time is V[2] and so on. I want to set it myself...How can I do it? this is the picture of my question

1

There are 1 answers

0
Filipe Teixeira On BEST ANSWER

So that is not the index of your vertex. It is the id of your vertex, and if you asking how can you set that, then the answer is that you can't. Titan sets the Ids internally and they are immutable.

What you can do however, is create your own index so you can do fast lookups. I would recommend starting with simple composite index.

You can create a composite index as follows:

graph = TitanFactory.open('conf.properties');
mgmt = graph.openManagement();
myId = mgmt.makePropertyKey("MY-ID").dataType(String.class).make();
mgmt.buildIndex('byMyID', Vertex.class).addKey(myId).buildCompositeIndex();
mgmt.commit();

The above will create a property called MY-ID and index it. Which means that any vertex with that property can be looked up quickly.

Side Note: Make sure you are initialising a Titan Graph not a Tinker Graph. Tinker Graphs do not support indexing.