我在使用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
< / strong>即可。这是怎么回事?当然(3)应该返回true
?我错误配置了什么吗?
答案 0 :(得分: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();
}