Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j 在现有节点之间创建关系的更快方法?_Neo4j_F#_Graph Databases_Neo4jclient - Fatal编程技术网

Neo4j 在现有节点之间创建关系的更快方法?

Neo4j 在现有节点之间创建关系的更快方法?,neo4j,f#,graph-databases,neo4jclient,Neo4j,F#,Graph Databases,Neo4jclient,我正在开发一个应用程序,其中我的neo4j数据库中只有“11263”个节点。 我使用以下cypher查询来形成节点之间的关系: let CreateRelations(fromToList : FromToCount list)= client.Cypher .Unwind(fromToList, "fromToList") .Match("(source)", "(target)") .Where("source.Id= fromToList.SId and t

我正在开发一个应用程序,其中我的neo4j数据库中只有“11263”个节点。 我使用以下cypher查询来形成节点之间的关系:

let CreateRelations(fromToList : FromToCount list)=
    client.Cypher
    .Unwind(fromToList, "fromToList")
    .Match("(source)", "(target)")
    .Where("source.Id= fromToList.SId and target.Id= fromToList.FId ")
    .Merge("(source)-[relation:Fights_With]->(target)")
    .OnCreate()
    .Set("relation.Count= fromToList.Count,relation.Date= fromToList.Date")
    .OnMatch()
    .Set("relation.Count= (relation.Count+ fromToList.Count )")
    .Set("relation.Date= fromToList.Date")
    .ExecuteWithoutResults()
在neo4j数据库中形成1000个关系大约需要47到50秒。
我是neo4j DB的新手,还有其他有效的方法吗?

让您慢下来的一个大问题是您没有使用查找起始节点。与
source
的匹配正在对数据库中的所有节点执行扫描,以在展开列表中的每行中查找可能的匹配项。然后它对
目标执行相同的操作

您需要在节点上添加标签,如果节点已经有标签,请在查询中使用标签。您需要在标签和
id
属性上设置索引或唯一约束,以便将索引用于查找


优化查询的最佳方法是在浏览器中试用它们,并使用EXPLAIN确保使用索引查找,如果仍然很慢,则在查询中使用PROFILE(它将执行查询)要在查询执行时查看生成的行和db命中数。

不应该
source.Id
target.Id
有不同的值吗?@cybersam键入错误,我已相应地编辑了帖子。感谢您的回复,我将进行建议的更改并更新结果。