2016-06-01 20 views
0

我使用Titan 1.0和elasticsearch作为后端。 从titan文档中,我了解到使用elasticsearch时,我们在构建索引时使用mixedIndex。 这是我的使用案例和问题: 我正在创建图书馆的注册数据的图形数据库,我有注册时间的数据以及其他个人信息,如姓名和年龄。我想查询在给定时间范围内注册的所有用户,换句话说,我希望查询的数字比较函数。这是我如何创建索引:Titan 1.0混合索引不能处理警告 - 查询需要迭代所有顶点

PropertyKey propertyKey = mgmt.makePropertyKey("registTime").dataType(Date.class) 
    .cardinality(Cardinality.SINGLE).make() 

timeIndex = mgmt.buildIndex("registeredTime",Vertex.class) 
    .addKey("registTime", Mapping.TEXTSTRING.asParameter()) 
    .buildMixedIndex("search"); 

的timeIndex创建成功,但是,当我想注册的时间查询:

g.V().has("registTime", gt("2015-01-01 00:00:00.000+0000")) 

它给了我:

WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [()]. For better performance, use indexes 

它给了我一个空的结果,虽然我用gremlin命令检查并确认数据就在那里。我做错了什么?我怎么解决这个问题?

回答

1

此错误表示索引尚未ENABLED

泰坦指数有INSTALLED,REGISTERED,ENABLEDDISABLED状态。欲了解更多信息,看看here

在使用之前,您需要将索引状态设置为ENABLED。否则,你会得到这个警告。

这是如何启用索引。

mgmt = graph.openManagement() 
mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.ENABLE).get() 
mgmt.commit() 

然后等待,直到它切换,

ManagementSystem.awaitGraphIndexStatus(graph, propertyKeyIndexName) 
        .status(SchemaStatus.ENABLED) 
        .timeout(10, ChronoUnit.MINUTES) // set timeout to 10 min 
        .call(); 

所以从现在开始,所有添加的数据将被编入索引。如果你想索引已经添加的数据:

mgmt = graph.openManagement() 
mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.REINDEX).get() 
mgmt.commit() 

欲了解更多,请阅读docs herehere

+0

感谢您的快速回复。我发现我的索引没有正确创建,不知是否因为数据类型(Date.class)。但我从泰坦文件了解到,混合索引也支持Date类型。如果我将其更改为String.class,它将被正确创建。 – RWM

+0

而且,即使它被正确创建,我在mgmt.updateIndex行(mgmt.getGraphIndex(“registeredTime”),SchemaAction.ENABLE_INDEX).get();下面也会得到NullPointerException。 。 – RWM

相关问题