Neo4j中的Match命令 [英] Match Command in Neo4j
问题描述
我有两个图,其中一些节点的标签相似.如果要使用match命令获取图的一部分,则需要指定图名称. 例如 MATCH(dom)<-[:headedby]-(Hd) 返回计数(名称);
I have two graphs with some nodes with similar labels. If I want to fetch part of a graph using match command,then do I need to specify the graph name. For eg., MATCH (dom)<-[:headedby]-(Hd) RETURN count (Hd.name);
在两个图中我都具有(dom)<-[:headedby]-(Hd)关系,那么它获取哪些数据? 我发现它给了我两个图的总计数. 请让我知道是否也必须使用match命令传递图形别名,以及操作方法.
I have (dom)<-[:headedby]-(Hd) relation in both the graphs, so which data does it fetch? I'm finding that it is giving me the aggregate count of both the graphs. Please let me know if I have to pass the graph alias also with the match command and how to do it.
谢谢.
这是对完整模型的导入查询:
This is the import query to the complete model:
LOAD CSV FROM "file:D:\\Neo4j\\demo2dbcopy.csv" AS emp
MERGE (cname:Cmpname {name: emp[0]})
MERGE (clusters:ClustName { name: emp [1]})
MERGE (dom:domains { name: emp [2]})
MERGE (Hd:Head { name: emp [3]})
MERGE (DelHd:DeliveryHead { name: emp [4]})
MERGE (Mgr:Managers { name: emp [5]})
MERGE (Emp:Employees { name: emp [6]})
CREATE (cname)-[:has]->(clusters),
(clusters)-[:contains]->(dom)<-[:headedby]-(Hd),
(Hd)-[:equals]->(DelHd),
(DelHd)-[:assistedby]->(Mgr),
(Mgr)-[:Dividesinto]->(Emp)
return cname,clusters,dom,Hd,DelHd,Mgr,Emp;
推荐答案
如果我理解这一点,则可以正确地在一个Neo4j数据库中包含多个子图.
If I understand this one correctly want to have multiple subgraphs in one Neo4j database.
我认为您的模型缺少子图的根节点.
I think your model is missing a root node for your subgraphs.
将CSV文件合并为一个,然后添加1列以分隔不同的子图. 然后,导入语句将如下所示:
Combine your CSV files to one and add 1 column to separate the different subgraphs. Then the import statement whould look like this:
LOAD CSV FROM "file:D:\\Neo4j\\demo2dbcopy.csv" AS emp
MERGE (root:SubGraph {source: emp[7]})
MERGE (cname:Cmpname {name: emp[0]})
MERGE (clusters:ClustName { name: emp [1]})
MERGE (dom:domains { name: emp [2]})
MERGE (Hd:Head { name: emp [3]})
MERGE (DelHd:DeliveryHead { name: emp [4]})
MERGE (Mgr:Managers { name: emp [5]})
MERGE (Emp:Employees { name: emp [6]})
CREATE (root)<-[:PART_OF_SUB_GRAPH]-(cname)-[:has]->(clusters),
(clusters)-[:contains]->(dom)<-[:headedby]-(Hd),
(Hd)-[:equals]->(DelHd),
(DelHd)-[:assistedby]->(Mgr),
(Mgr)-[:Dividesinto]->(Emp)
return root,cname,clusters,dom,Hd,DelHd,Mgr,Emp;
您可能想要执行以下操作:
You probably want to do something like this:
从子图"csv1"中查找所有域,并返回Heads的计数
Find all domains from the sub graph "csv1" and return the count of Heads
MATCH (root:SubGraph {source: "csv1"})<--(:Cmpname)-->(:ClustName)-->(dom:domains {name:"foo"})<-[:headedby]-(hd) RETURN dom.name, count (hd.name);
更新:在此合并此问题的答案:区分Neo4j查询以获取不同的数据文件
UPDATE: combining the answers of this question en this one here: Differentiating Neo4j queries for different data files
这篇关于Neo4j中的Match命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!