简体   繁体   中英

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

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? 这是我的问题的照片

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM