对点上的属性创建索引,注意:We can retrieve it from the index using the getVertices(String,Object)
method:
TitanGraph g = TitanFactory.open("/tmp/titan");
g.createKeyIndex("name",Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno = g.getVertices("name","juno").iterator().next();
(常用这种:Iterable< Vertex > results = g.getVertices("name","juno") )
对边上的属性创建索引:
g.createKeyIndex("time",Edge.class);
Vertex jena = g.addVertex(null);
jena.setProperty("name", "jena");
Edge e = jena.addEdge("knows",juno);
e.setProperty("time",99);
g.getEdges("time",99).iterator().next();
Titan的官网上说必须首先建立索引,之后才能写入数据: Key indices need to be created before the key is first used。但是我测试Gremlin.sh发现可以先写数据再建索引。