2

我在索引与 Titan 一起工作时遇到了一些麻烦。我配置我的索引如下:

TitanGraph graph = TitanFactory.open("conf/titan-cassandra-es.properties");
TitanManagement management = graph.openManagement();
String indexKey = "byItemIdentifier";
String propertyKey = "ITEM_IDENTIFIER";
TitanIndex index = management.getGraphIndex(indexKey);
PropertyKey key = management.makePropertyKey(propertyKey).dataType(String.class).make();
management.buildIndex(indexKey, Vertex.class).addKey(key, Mapping.STRING.asParameter()).buildMixedIndex("search");
management.commit();

现在的问题:

Vertex vertex = graph.addVertex();
vertex.property(propertyKey, "www.foo.com/bar");
graph.commit();

然后稍后我尝试以下操作:

graph.traversal().V().has(propertyKey, "foo").hasNext(); //(1)
graph.traversal().V().has(propertyKey, "bar").hasNext(); //(2)
graph.traversal().V().has(propertyKey, "www.foo.com/bar").hasNext(); //(3)

(1) =false , (2) =false(3) =false。这是怎么回事?当然(3)应该返回true?我是否配置错误?

4

1 回答 1

0

首先,在您创建索引之后,您应该等待它从已安装到已注册。这种方法会有所帮助:

// Block until the SchemaStatus transitions from INSTALLED to REGISTERED
ManagementSystem.awaitGraphIndexStatus(graph, vertices_index).status(SchemaStatus.REGISTERED).call();

这会阻止您的代码,直到您的索引后端创建它。

其次,如果图中已经有一些数据,您必须重新索引您的属性,以便索引后端(Elasticsearch 等)可以知道它。使用这个 Java 方法:

public static void reindexGraph(TitanGraph graph, String myIndex) throws InterruptedException {
    TitanManagement management = graph.openManagement();
    TitanGraphIndex index = management.getGraphIndex(myIndex);
    management.updateIndex(index, SchemaAction.REINDEX);
    management.commit();

    // Enable the index
    ManagementSystem.awaitGraphIndexStatus(graph, myIndex).status(SchemaStatus.ENABLED).call();
    graph.tx().commit();
}
于 2016-01-15T00:44:13.450 回答