问题
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);
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.
Thanks in advance.
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;
回答1:
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.
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:
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);
UPDATE: combining the answers of this question en this one here: Differentiating Neo4j queries for different data files
回答2:
I have used the following query in response to above syntax but it is returning me 0 rows where the correct answer must be 7 rows.
MATCH (root:SubGraph {source: "demo2db"})<--(clusters:ClustName{name:"ABC"})-[:contains]->(dom:domains {name:"XYZ"}) RETURN count(dom.name);
来源:https://stackoverflow.com/questions/24751634/match-command-in-neo4j