Neo4j批插入器计数失败,我该怎么办?

Neo4j批插入器计数失败,我该怎么办?,neo4j,Neo4j,我正在使用以下代码将数据批量插入neo4j数据库,但在我运行代码后,密码“匹配(n)返回计数(n)”返回0。我尝试了很多次,但没有成功,您能帮助我吗?非常感谢 int denseNodeThreshold = GraphDatabaseSettings.dense_node_threshold.defaultValue(); DatabaseLayout tempStoreDir = ((GraphDatabaseAPI)graphDb).databaseLayout(); fi

我正在使用以下代码将数据批量插入neo4j数据库,但在我运行代码后,密码“匹配(n)返回计数(n)”返回0。我尝试了很多次,但没有成功,您能帮助我吗?非常感谢

int denseNodeThreshold = GraphDatabaseSettings.dense_node_threshold.defaultValue();
    DatabaseLayout tempStoreDir = ((GraphDatabaseAPI)graphDb).databaseLayout();
    final FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
    batchInserter = BatchInserters.inserter(tempStoreDir, fileSystem, configuration(denseNodeThreshold));
    batchInserter.createDeferredSchemaIndex(personLabel).on("name").create();
    final ArrayList<Long> nodeIds = new ArrayList<>();
    //没有索引,通过Neo4j Desktop打开左侧没有 Node Labels和Relationship Types,有索引的情况下,count为0
    for(int i=0; i<1e5; i++){
        Map<String, Object> properties = new HashMap<>();
        properties.put( "name", UUID.randomUUID().toString() );
        long nodeId = batchInserter.createNode( properties, personLabel );
        nodeIds.add(nodeId);
    }
    final Random random = new Random();
    for(int i=0; i<1e3; i++){
        Long from = nodeIds.get((random.nextInt() % nodeIds.size() + nodeIds.size()) % nodeIds.size());
        Long to = nodeIds.get((random.nextInt() % nodeIds.size() + nodeIds.size()) % nodeIds.size());
        batchInserter.createRelationship( from, to, knows, null );
    }
int denseNodeThreshold=GraphDatabaseSettings.dense\u node\u threshold.defaultValue();
DatabaseLayout tempStoreDir=((GraphDatabaseAPI)graphDb.DatabaseLayout();
final FileSystemAbstraction fileSystem=new DefaultFileSystemAbstraction();
batchInserter=BatchInserters.inserter(tempStoreDir、文件系统、配置(denseNodeThreshold));
batchInserter.createDeferredSchemaIndex(personLabel).on(“名称”).create();
final ArrayList nodeIds=新的ArrayList();
//没有索引,通过Neo4j桌面打开左侧没有 节点标签和关系类型有索引的情况下,计数为0
对于(inti=0;i欢迎

无法使用进程内服务器,因为每次关闭后都会删除其文件,这解释了为什么重新启动时计数始终为0

另一方面,您应该使用try-with-resources块关闭
BatchInserter
,以确保在创建完节点和关系后刷新更改:

try(BatchInserter-BatchInserter=BatchInserters.inserter(tempStoreDir、文件系统、配置(denseNodeThreshold))){
// [...]
}

非常感谢。我更改了代码并按您的方式运行。它仍然算失败。可以在此处找到代码。