Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Titan db how to list all graph indexes

I've been looking at the management system but some things still elude me. Essentially what I want to do is:

  • List all Edge based indexes (including vertex centric).
  • List all Vertex based indexes (on a per label basis if the index is attached to a label).

It's basically like mapping out the graph schema.

I've tried a few things but I only get partial data at best.

g.getIndexdKeys(<Vertex or Edge>); 
//basic information. Doesn't seem to return any buildEdgeIndex() based indexes

mgmt.getVertexLabels(); 
// gets labels, can't find a way of getting indexes attached to these labels.

mgmt.getGraphIndexes(Vertex.class); 
// works nicely I can retrieve Vertex indexes and get pretty much any 
// information I want out of them except for information regarding 
// indexOnly(label). So I can't tell what label these indexes are attached to.

mgmt.getGraphIndexes(Edge.class); 
// doesn't seem to return any buildEdgeIndex() indexes.

Any help filling the void would be helpful.

Id like to know:

  • How can I find the indexes attached to a label (or label attached to an index) via indexOnly()
  • How do I list the edge indexes set via buildEdgeIndex() and their respective edge Labels?

Thanks in advance.

Extra information: Titan 0.5.0, Cassandra backend, via rexster.

like image 522
Pomme.Verte Avatar asked Sep 06 '14 16:09

Pomme.Verte


1 Answers

it's not really straight forward, hence I'm going to show it using an example.

Let's start with the Graph of the Gods + an additional index for god names:

g = TitanFactory.open("conf/titan-cassandra-es.properties")
GraphOfTheGodsFactory.load(g)
m = g.getManagementSystem()
name = m.getPropertyKey("name")
god = m.getVertexLabel("god")
m.buildIndex("god-name", Vertex.class).addKey(name).unique().indexOnly(god).buildCompositeIndex()
m.commit()

Now let's pull the index information out again.

gremlin> m = g.getManagementSystem()
==>com.thinkaurelius.titan.graphdb.database.management.ManagementSystem@2f414e82

gremlin> // get the index by its name
gremlin> index = m.getGraphIndex("god-name")
==>com.thinkaurelius.titan.graphdb.database.management.TitanGraphIndexWrapper@e4f5395

gremlin> // determine which properties are covered by this index
gremlin> gn.getFieldKeys()
==>name

//
// the following part shows what you're looking for
//
gremlin> import static com.thinkaurelius.titan.graphdb.types.TypeDefinitionCategory.*

gremlin> // get the schema vertex for the index
gremlin> sv = m.getSchemaVertex(index)
==>god-name

gremlin> // get index constraints
gremlin> rel = sv.getRelated(INDEX_SCHEMA_CONSTRAINT, Direction.OUT)
==>com.thinkaurelius.titan.graphdb.types.SchemaSource$Entry@5162bf3

gremlin> // get the first constraint; no need to do a .hasNext() check in this
gremlin> // example, since we know that we will only get a single entry
gremlin> sse = rel.iterator().next()
==>com.thinkaurelius.titan.graphdb.types.SchemaSource$Entry@5162bf3

gremlin> // finally get the schema type (that's the vertex label that's used in .indexOnly())
gremlin> sse.getSchemaType()
==>god

Cheers, Daniel

like image 109
Daniel Kuppitz Avatar answered Oct 26 '22 08:10

Daniel Kuppitz