We have defined 5 indexes using titan cassandra in the follow block of code
def mgmt = g.managementSystem;
try {
if (!mgmt.containsGraphIndex("byId")) {
def key = mgmt.makePropertyKey('__id').dataType(String.class).make()
mgmt.buildIndex("byId",Vertex.class).addKey(key).buildCompositeIndex()
}
if (!mgmt.containsGraphIndex("byType")) {
def key = mgmt.makePropertyKey('__type').dataType(String.class).make()
mgmt.buildIndex("byType",Vertex.class).addKey(key).buildCompositeIndex()
}
if (!mgmt.containsGraphIndex("lastName")) {
def key = mgmt.makePropertyKey('lastName').dataType(String.class).make()
mgmt.buildIndex('lastName',Vertex.class).addKey(key).buildMixedIndex(INDEX_NAME)
}
if (!mgmt.containsGraphIndex("firstName")) {
def key = mgmt.makePropertyKey('firstName').dataType(String.class).make()
mgmt.buildIndex('firstName',Vertex.class).addKey(key).buildMixedIndex(INDEX_NAME)
}
if (!mgmt.containsGraphIndex("vin")) {
def key = mgmt.makePropertyKey('vin').dataType(String.class).make()
mgmt.buildIndex('vin',Vertex.class).addKey(key).buildMixedIndex(INDEX_NAME)
}
mgmt.commit()
} catch (Exception e) {
System.err.println("An error occurred initializing indices")
e.printStackTrace()
}
we then execute the following query
g.V.has('__id','49fb8bae5f994cf5825b849a5dd9b49a')
This produces a warning informing us that :
"Query requires iterating over all vertices [{}]. For better performance, use indexes"
I'm confused because according to the documentation these indexes are set up correctly, but for some reason titan is not using them.
The indexes are created before any data is in the graph, so reindexing is not neccessary. Any help is greatly appreciated.
Update- I've managed to break this down into a very simple test. In our code we have developed a custom gremlin step to use for the stated query
Gremlin.defineStep('hasId', [Vertex,Pipe], { String id ->
_().has('__id', id)
})
then from our code we call
g.V.hasId(id)
It appears that when we use the custom gremlin step the query does not use the index, but when using the vanilla gremlin call the index is used.
It looks like a similar oddity was noted in this post https://groups.google.com/forum/#!topic/aureliusgraphs/6DqMG13_4EQ