【问题标题】:Titan 1.0 mixed index is not working with warning - Query requires iterating over all verticesTitan 1.0 混合索引不适用于警告 - 查询需要遍历所有顶点
【发布时间】:2023-09-29 14:59:01
【问题描述】:

我使用 Titan 1.0 和 elasticsearch 作为后端。 从 Titan 文档中,我了解到使用 elasticsearch 时,我们在构建索引时使用了混合索引。 这是我的用例和问题: 我正在为书店的注册数据、我有注册时间的数据以及姓名和年龄等其他个人信息创建一个图形数据库。我想查询在给定时间范围内注册的所有用户,换句话说,我想要一个查询的数字比较函数。这就是我创建索引的方式:

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 命令检查并确认数据就在那里。我做错什么了吗?我该如何解决这个问题?

【问题讨论】:

    标签: elasticsearch indexing titan tinkerpop3


    【解决方案1】:

    这个错误意味着索引还不是ENABLED

    Titan 索引具有INSTALLEDREGISTEREDENABLEDDISABLED 状态。欲了解更多信息,请查看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

    【讨论】:

    • 感谢您的快速回复。我发现我的索引没有正确创建,不知道是不是因为数据类型(Date.class)。但是我从 Titan 文档中了解到混合索引也支持 Date 类型。如果我将其更改为 String.class 它将被正确创建。
    • 而且,即使它是正确创建的,我在 mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.ENABLE_INDEX).get(); .