I am trying to translate a process map made in Visio, into nodes mapped in Neo4j. The nodes are all of the same type, but the property for process number varies.
So far I have this:
LOAD CSV WITH HEADERS FROM "file:/Book111.csv" AS line
CREATE (p:Stage {name: line.MasterName, id: line.ProcessNumber})
RETURN p
I get that I have more nodes because i've double up the query, but I need the relationship links between the nodes. Surely one component should be to define the relationship itself?
Ah, well perhaps what i'm trying to do simply isn't possible then. I only have one node type. I want to create relationships between the same node type dependant on a unique numeric value property "ProcessNumber". So if "ProcessNumber has the value "1", it might have a relationship "ComesBefore" p with value "2" for "ProcessNumber". (p"1")-[:ABC]->(p"2")
If you want to link all your existing nodes, you can use apoc.nodes.link. Here's the Cypher to do that.
MATCH (p:Stage)
WITH p order by p.id ASC
WITH collect(p) as p1
CALL apoc.nodes.link(p1, 'NEXT')
RETURN p
This will connect all the selected nodes with 'NEXT' relationship and visually you see a train of nodes.
Aha, so this is exactly what i'm trying to do - order by p.id. But, when I try to put the lines in the order you have it:
LOAD CSV WITH HEADERS FROM "file:/Book111.csv" AS line
CREATE (p:Stage {name: line.MasterName, id: line.ProcessNumber})
MATCH (p:Stage)
WITH p order by p.id ASC
WITH collect(p) as p1
CALL apoc.nodes.link(p1, 'NEXT')
RETURN p
When you start Neo4j Desktop you will see your a box with the database name you created. On this box there will be three circles at right top corner. Click on it and select Manage from the drop down list. Next you will see another window and on that click on Plugins tab. In that tab you will see APOC and click on install button. That does the job. Restart you database and play.
Very nice . The only thing now is that it's making one relationship for every node, between each node (there are 17 nodes and between each node there are 17 relationships')
gosh, I'm sorry that this turned into such an epic. I've uninstalled and got the latest version from the website. The version that installed is 1.3.11, but when I create a database it creates a 4.1.3 file:
Thanks to you both for your help @ameyasoft & @clem. It seems like there are some pretty big problems with newer versions of Neo4j on windows 10, so i just went back to 1.2.8.
I managed to get the query working with a couple of small adjustments:
LOAD CSV WITH HEADERS FROM "file:/Book1.csv" AS line
CREATE (p:Person {id: line.ProcessNumber, name: line.MasterName})
WITH p order by p.id ASC
WITH collect(p) as p1
CALL apoc.nodes.link(p1, 'NEXT')
RETURN p1