如何获取Titan中的索引键列表?

时间:2013-08-28 19:19:28

标签: gremlin titan

我正在使用Titan v0.3.1,并希望看到我已经通过createKeyIndex索引的键列表。我怎么能这样做?

2 个答案:

答案 0 :(得分:5)

在Gremlin shell中,您可以使用蓝图'KeyIndexableGraph getIndexedKeys功能:

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

my_key_1my_key_2my_key_3是3个索引顶点键)

要抓取边缘键的索引,请使用Edge.class代替上面的Vertex.class

答案 1 :(得分:4)

正如您自己找到的那样,您可以使用蓝图getIndexedKeys(Vertex.class)方法,但Titan类型系统提供的内容远远超过createKeyIndex。使用Titan的时间越长,您就越想了解Type Maker系统:

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

在这种情况下,getIndexedKeys返回的类型可能不够。这里有一些Gremlin可以为您提供更多详细信息:

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]

您可能需要查看Titan API,以获取有关从TitanKey调用返回的getVertices的更多信息(因为类型存储为顶点):

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