如何解决通过本机api创建索引的neo4j问题
我试图通过本机api为neo4j图创建索引,并且我正在使用org.neo4j:neo4j:3.4.4
,这是我的代码:
public static Boolean createIndex(GraphDatabaseService graphDb,Label label,String property){
Boolean ret = true;
try {
// END SNIPPET: startDb
{
// START SNIPPET: createIndex
IndexDefinition indexDefinition;
try (Transaction tx = graphDb.beginTx()) {
Schema schema = graphDb.schema();
indexDefinition = schema.indexFor(label)
.on(property)
.create();
tx.success();
tx.close();
}
// END SNIPPET: createIndex
// START SNIPPET: wait
try (Transaction tx = graphDb.beginTx()) {
Schema schema = graphDb.schema();
schema.awaitIndexOnline(indexDefinition,1000,TimeUnit.SECONDS);
tx.success();
tx.close();
}
// END SNIPPET: wait
// START SNIPPET: progress
try (Transaction tx = graphDb.beginTx()) {
Schema schema = graphDb.schema();
System.out.println(String.format("Percent complete: %1.0f%%",schema.getIndexPopulationProgress(indexDefinition).getCompletedPercentage()));
tx.success();
tx.close();
}
// END SNIPPET: progress
}
} catch (ConstraintViolationException e) {
System.out.println(e);
ret = true;
}
catch (Exception e){
System.out.println(e);
ret = false;
};
return ret;
}
此代码完全来自official example,我可以看到代码中记录的日志Percent complete: 100%
。但是,当我使用neo4j浏览器打开图形并查询:schema
时,它表示索引仍在填充,这意味着schema.getIndexPopulationProgress(indexDefinition)
方法实际上不起作用。
我想问的是,有什么解决方案可以查询索引的真实状态,或者有什么想法可以同步创建索引,而不是异步创建官方方法。
感谢您的时间!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。