How can I get a list of indexed keys in Titan?
Asked Answered
H

2

5

I am using Titan v0.3.1 and would like to see a list of which keys I have already indexed via createKeyIndex. How can I do this?

Halliehallman answered 28/8, 2013 at 19:19 Comment(0)
A
4

As you found for yourself you can use the Blueprints getIndexedKeys(Vertex.class) method for this, however the Titan type system has a lot more to offer than createKeyIndex. The longer you work with Titan the more you will want to learn about the Type Maker system:

https://github.com/thinkaurelius/titan/wiki/Type-Definition-Overview

In that case the types returned by getIndexedKeys may not be enough. Here's some Gremlin to get you more details:

gremlin> g = GraphOfTheGodsFactory.create('/tmp/titan')
13/08/28 16:28:23 INFO diskstorage.Backend: Configuring index [search] based on: 
...
13/08/28 16:28:25 INFO cluster.metadata: [Astaroth / Asteroth] [titan] update_mapping [vertex] (dynamic)
==>titangraph[local:/tmp/titan]
gremlin> import static com.thinkaurelius.titan.graphdb.types.system.SystemKey.*
==>import com.tinkerpop.gremlin.*
==>import com.tinkerpop.gremlin.java.*
==>import com.tinkerpop.gremlin.pipes.*
==>import com.tinkerpop.gremlin.pipes.filter.*
==>import com.tinkerpop.gremlin.pipes.sideeffect.*
==>import com.tinkerpop.gremlin.pipes.transform.*
...
==>import static com.thinkaurelius.titan.graphdb.types.system.SystemKey.*
gremlin> import com.thinkaurelius.titan.graphdb.types.*
==>import com.tinkerpop.gremlin.*
==>import com.tinkerpop.gremlin.java.*
==>import com.tinkerpop.gremlin.pipes.*
==>import com.tinkerpop.gremlin.pipes.filter.*
==>import com.tinkerpop.gremlin.pipes.sideeffect.*
==>import com.tinkerpop.gremlin.pipes.transform.*
...
==>import com.thinkaurelius.titan.graphdb.types.*
gremlin> g.newTransaction().getVertices(TypeClass, TitanTypeClass.KEY).collect{[it.name,it.dataType]}
==>[reason, class java.lang.String]
==>[name, class java.lang.String]
==>[type, class java.lang.String]
==>[time, class java.lang.Integer]
==>[place, class com.thinkaurelius.titan.core.attribute.Geoshape]
==>[age, class java.lang.Integer]

You might want to look at the Titan API for more information on the TitanKey that is returned from that call to getVertices (as types are stored as vertices):

http://thinkaurelius.github.io/titan/javadoc/0.3.2/com/thinkaurelius/titan/core/TitanKey.html

Apeak answered 28/8, 2013 at 20:52 Comment(1)
This is great, thanks @stephen-mallette. You're right about Titan's other types: I have already been exploring the ElasticSearch integration with Titan for more advanced indexes & searching.Halliehallman
H
5

In the Gremlin shell, you can use Blueprints' KeyIndexableGraph getIndexedKeys function:

gremlin> g.getIndexedKeys(Vertex.class)
==>my_key_1
==>my_key_2
==>my_key_3

(my_key_1, my_key_2, and my_key_3 are the 3 indexed vertex keys)

To grab the indexes for keys on edges, use Edge.class in place of Vertex.class above.

Halliehallman answered 28/8, 2013 at 19:19 Comment(0)
A
4

As you found for yourself you can use the Blueprints getIndexedKeys(Vertex.class) method for this, however the Titan type system has a lot more to offer than createKeyIndex. The longer you work with Titan the more you will want to learn about the Type Maker system:

https://github.com/thinkaurelius/titan/wiki/Type-Definition-Overview

In that case the types returned by getIndexedKeys may not be enough. Here's some Gremlin to get you more details:

gremlin> g = GraphOfTheGodsFactory.create('/tmp/titan')
13/08/28 16:28:23 INFO diskstorage.Backend: Configuring index [search] based on: 
...
13/08/28 16:28:25 INFO cluster.metadata: [Astaroth / Asteroth] [titan] update_mapping [vertex] (dynamic)
==>titangraph[local:/tmp/titan]
gremlin> import static com.thinkaurelius.titan.graphdb.types.system.SystemKey.*
==>import com.tinkerpop.gremlin.*
==>import com.tinkerpop.gremlin.java.*
==>import com.tinkerpop.gremlin.pipes.*
==>import com.tinkerpop.gremlin.pipes.filter.*
==>import com.tinkerpop.gremlin.pipes.sideeffect.*
==>import com.tinkerpop.gremlin.pipes.transform.*
...
==>import static com.thinkaurelius.titan.graphdb.types.system.SystemKey.*
gremlin> import com.thinkaurelius.titan.graphdb.types.*
==>import com.tinkerpop.gremlin.*
==>import com.tinkerpop.gremlin.java.*
==>import com.tinkerpop.gremlin.pipes.*
==>import com.tinkerpop.gremlin.pipes.filter.*
==>import com.tinkerpop.gremlin.pipes.sideeffect.*
==>import com.tinkerpop.gremlin.pipes.transform.*
...
==>import com.thinkaurelius.titan.graphdb.types.*
gremlin> g.newTransaction().getVertices(TypeClass, TitanTypeClass.KEY).collect{[it.name,it.dataType]}
==>[reason, class java.lang.String]
==>[name, class java.lang.String]
==>[type, class java.lang.String]
==>[time, class java.lang.Integer]
==>[place, class com.thinkaurelius.titan.core.attribute.Geoshape]
==>[age, class java.lang.Integer]

You might want to look at the Titan API for more information on the TitanKey that is returned from that call to getVertices (as types are stored as vertices):

http://thinkaurelius.github.io/titan/javadoc/0.3.2/com/thinkaurelius/titan/core/TitanKey.html

Apeak answered 28/8, 2013 at 20:52 Comment(1)
This is great, thanks @stephen-mallette. You're right about Titan's other types: I have already been exploring the ElasticSearch integration with Titan for more advanced indexes & searching.Halliehallman

© 2022 - 2024 — McMap. All rights reserved.