I just push text corpus into Neo4j database. When I execute MATCH (n) RETURN n
Cypher query, it returns multiple nodes with the same name. how can I merge these nodes as one?
nodes having same name
Your name values have different values because of upper and lower case letters ("Java" and "java" are different).
I reproduced your scenario creating a sample data set:
CREATE (n1:Node {name : "Java"}),
(n2:Node {name : "Java"}),
(n3:Node {name : "java"}),
(n1)-[:TYPE]->(),
(n1)-[:TYPE]->(),
(n1)-[:TYPE]->(),
(n2)-[:TYPE]->(),
(n2)-[:TYPE]->(),
(n3)-[:TYPE]->()
The above query will produce this graph:
To merge all "Java" nodes you can use the APOC Procedure apoc.refactor.mergeNodes(nodes)
. Running the following query:
MATCH (n:Node)
// using toLower function to group nodes with the same name but
// different cases (eg Java, java, javA)
WITH toLower(n.name) as name, collect(n) as nodes
// passing the nodes collection to mergeNodes APOC procedure
CALL apoc.refactor.mergeNodes(nodes) yield node
RETURN *
Will update your graph to:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With