如何从 Java 代码中的 Cypher 查询中获取 db-hits 总数?

How to get total number of db-hits from Cypher query within a Java code?

我正在尝试从我的 Cypher 查询中获取 db-hits 的总数。出于某种原因,调用这个时我总是得到 0:

String query = "PROFILE MATCH (a)-[r]-(b)-[p]-(c)-[q]-(a) RETURN a,b,c";
Result result = database.execute(query);
while (result.hasNext()) {
    result.next();
}
System.out.println(result.getExecutionPlanDescription().getProfilerStatistics().getDbHits());

数据库似乎没问题。是不是达到这个值的方式有问题?

ExecutionPlanDescription是一个树状结构。最有可能的是 top 元素本身不会直接访问数据库,例如投影。

因此您需要使用 ExecutionPlanDescription.getChildren() 编写递归函数来钻取查询计划的各个部分。例如。如果 children(或 sub*-children)之一是 Expand 类型的计划,您可以使用 plan.getProfilerStatistics().getDbHits().