嵌入式开发利用cypher怎么使用apoc
发布于 10 个月前 作者 fanzetian930716 1152 次浏览 来自 问答

我的neo4j版本为3.3.2 相关算法需要apoc的函数,我成功引入apoc在浏览器命令行里可以成功执行遍历,语句为:

MATCH (c:Character) WITH collect© AS characters CALL apoc.algo.betweenness([‘INTERACTS’], characters, ‘BOTH’) YIELD node, score SET node.betweenness = score RETURN node.name AS name, score ORDER BY score DESC

现在java代码中嵌入式访问数据库利用GraphDatabaseService的execute方法执行上述语句,会报错: there is no procedure with the name ‘apoc.algo.betweenness’ registered for this database instance. 各位大神这该如何解决?

3 回复

execute 没问题啊,如下,可以正常运行:

package com.app.components;
@Component
public class Neo4jWarmup {
    private static final Logger LOG = LogManager.getLogger(StartupTasks.class);
    @Autowired
    GraphDatabaseService db;
    /*
     * this did the trick - the method gets called 
     * after Spring initialization and the DB works as expected
     */
    @Autowired 
    public void neo4jWarmup() {
        executeTestSelect();
    }
    private void executeTestSelect() {
        LOG.info("Warming up Neo4j...");
        Transaction tx = db.beginTx();
        db.execute("CALL apoc.warmup.run()");
        tx.close();
        LOG.info("Warmup complete.");
    }
}

你的报错是你的neo4j中没有apoc.algo.betweennes这个存储过程,安装这个存储过程或自己去创建吧

@pangguoming 我去执行你这个存储过程也报这类错误 是不是获取neo4j数据库实例的时候要读取相关配置的?我直接启动没有像网上说的 new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File("##")).oadPropertiesFromFile("##").newGraphDatabase()这样,直接newEmbeddedDatabase()没读配置

回到顶部