buildMixedIndex('bylastNameDOBEmail',['lastName','birthDate','email'],g)
buildMixedIndex('lastName',['lastName'],g)
buildMixedIndex('firstName',['firstName'],g)
buildMixedIndex('email',['email'],g)
buildMixedIndex('birthDate',['birthDate'],g)
buildMixedIndex('zip',['zip'],g)
buildMixedIndex('vin',['vin'],g)
private static void buildMixedIndex(String name, List<String> properties, TitanGraph g){
TitanManagement mgmt = g.openManagement()
try{
if(!mgmt.containsGraphIndex(name)){
def indexBuilder = mgmt.buildIndex(name,Vertex.class)
properties.each{
def key = mgmt.getPropertyKey(it)
if(!key){
logger.info("Creating key " + it)
key = mgmt.makePropertyKey(it).dataType(String.class).make()
}
indexBuilder.addKey(key)
}
indexBuilder.buildMixedIndex(INDEX_NAME)
mgmt.commit()
g.tx().commit()
logger.info("Created mixed index: " + name + ", on properties: " + properties.toString())
ManagementSystem.awaitGraphIndexStatus(g,name).status(SchemaStatus.ENABLED).call()
}
def indexSize = g.indexQuery(name,"v."+properties[0]+":*").limit(100).vertices().size()
logger.info(name + " index size is " + indexSize)
if(indexSize < 100){ //index is empty so reindex, should only get hit when creating new indices or when recovering elasticsearch
logger.info('Reindexing '+ name)
mgmt = g.openManagement()
def i = mgmt.getGraphIndex(name)
mgmt.updateIndex(i, SchemaAction.REINDEX)
mgmt.commit()
g.tx().commit()
// Enable the index
ManagementSystem.awaitGraphIndexStatus(g,name).status(SchemaStatus.ENABLED).call()
}
} finally {
if(mgmt.isOpen())
mgmt.commit()
g.tx().commit()
}
}