For the following gremlin script on titan db:


How can I using titan index on the query criteria: has("age",gt(10)) to speed up the query?


If you create the index before you upload your data (the best approach so you don't have to reindex existing data), then Titan will automatically use that index while answering your query (note 1 below):

The following code was pulled from Titan docs

graph.tx().rollback()  //Never create new indexes while a transaction is active
mgmt = graph.openManagement()
name = mgmt.getPropertyKey('age')
mgmt.buildIndex('ageIndex', Vertex.class).addKey(age).buildMixedIndex("<indexingbackendname>")

1: Titan’s query optimizer attempts to pick the most efficient index for any given traversal.

If you read under "Vertex-centric index" in those Titan docs, it has an example where the relevant index created is to quicken the second has clause (even though it is an edge index-- same principal).

  • 1
    To add a bit to this correct answer: If you don't need to check against ranges, i.e. gt(x) is not needed, then you can just use simpler Composite Indices which don't need an indexing backend. – Filipe Teixeira Sep 12 '16 at 8:48

Your Answer

