简体   繁体   English

TitanDB定义和使用索引

[英]TitanDB Defining and Using Indexes

Using this . 使用这个 I am constructing the following index: 我正在构建以下索引:

TitanManagement management = graph.openManagement();

PropertyKey key = management.makePropertyKey("ITEM_IDENTIFIER").dataType(String.class).make();

management.buildIndex("byItemIdentifier", Vertex.class).addKey(key).buildCompositeIndex();

management.commit();

However when I run the following query: 但是,当我运行以下查询时:

graph.traversal().V().has("ITEM_IDENTIFIER", "Test");

I still get the warning: 我仍然收到警告:

Query requires iterating over all vertices [(ITEM_IDENTIFIER = Test)]. For better performance, use indexes

How can I get TitanDB to use the index in order to speed up the lookups ? 我如何让TitanDB使用索引来加快查找速度?

So I managed to figure out the issue. 因此,我设法找出了问题所在。 Thanks to this answer providing more info. 由于此答案提供了更多信息。

The problem is that I assumed that I would use a CompositeIndex but after more careful reading of Chapter 20 , Chapter 22 , and Chapter 28 I was actually wrong. 问题是我假设我将使用CompositeIndex但是在更仔细地阅读了第20 第22 章和第28 章之后 ,我实际上是错误的。 String based indexes require a MixedIndex . 基于String的索引需要MixedIndex

To get MisedIndexes working with strings I had to first install Elasticsearch to enable String based indexes. 为了使MisedIndexes使用字符串,我必须首先安装Elasticsearch以启用基于String的索引。 Then I was able to configure my index by replacing: 然后,我可以通过替换配置索引:

management.buildIndex("byItemIdentifier", Vertex.class).addKey(key).buildCompositeIndex();

with

management.buildIndex("byItemIdentifier", Vertex.class).addKey(key, Mapping.STRING.asParameter()).buildMixedIndex("search");

after doing this the warning disappeared. 完成此操作后,警告消失。 I am going to do more testing to confirm this worked but for now this seems to have solved my issue. 我将做更多测试以确认此方法是否有效,但目前看来这已经解决了我的问题。

Your index definition looks reasonable, but there are a couple reasons the index might not be used you should check. 您的索引定义看起来很合理,但是有几个原因可能会导致您不使用索引,因此您应该检查一下。

The index has to finish building. 索引必须完成构建。

mgmt.awaitGraphIndexStatus(graph, "byItemIdentifier").call()

Or you need to reindex your existing data 或者您需要重新索引现有数据

mgmt.updateIndex(mgmt.getGraphIndex("byItemIdentifier"), SchemaAction.REINDEX).get()

Note that this latter operation should be completed inside a transaction. 请注意,后一个操作应在事务内完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM