Hi Damian,
You
must close transactions between defining a new index and attempting to
reindex it. Don't use the sequence of management operations quoted above. Attempting to define and reindex in the same transaction is
where you run into trouble. Here's the relevant doc chapter:
http://s3.thinkaurelius.com/docs/titan/1.0.0/indexes.html. Also, here are some commands showing how to approach this:
// cd titan-1.0.0-hadoop1
// rm -rf ./db
// bin/titan.sh start
// bin/gremlin.sh
// Start Titan against C* + ES and define a propert key called "foo"
graph = TitanFactory.open("conf/titan-cassandra-es.properties")
mgmt = graph.openManagement()
pkey = mgmt.makePropertyKey("foo").dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.commit()
// Add a vertex with the property key set to "bar"
graph.addVertex("foo","bar")
graph.tx().commit()
// Define a composite graph index on the property key created above
mgmt = graph.openManagement()
pkey = mgmt.getPropertyKey("foo")
mgmt.buildIndex("index", Vertex.class).addKey(pkey).buildCompositeIndex()
mgmt.commit()
// Wait for the index to transition from INSTALLED to REGISTERED
import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem
ManagementSystem.awaitGraphIndexStatus(graph, "index").call()
// The await call() must return something like this:
// ==>GraphIndexStatusReport[success=true, indexName='index', targetStatus=REGISTERED, notConverged={}, converged={foo=REGISTERED}, elapsed=PT0.009S]
// the success property must be true (implying that notConverged is empty)
// Retrieve a vertex by property condition foo=bar;
// this logs a linear scan warning because we haven't reindexed yet,
// and the index doesn't know about any properties that predate it
graph.query().has("foo", "bar").vertices()
// Reindex
mgmt = graph.openManagement()
index = mgmt.getGraphIndex("index")
mgmt.updateIndex(index, SchemaAction.REINDEX).get()
mgmt.commit()
// Reopen Titan and retrieve a vertex by property condition foo=bar;
// this hits the index and does not log a linear scan warning
graph.close()
graph = TitanFactory.open("conf/titan-cassandra-es.properties")
graph.query().has("foo", "bar").vertices()
// Note: the index's status has transitioned from
// REGISTERED to ENABLED as part of the REINDEX action
mgmt = graph.openManagement()
pkey = mgmt.getPropertyKey("foo")
index = mgmt.getGraphIndex("index")
index.getIndexStatus(pkey) // ENABLED
mgmt.rollback()
thanks,
Dan