Ordering nodes by property

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

Which gives me this:

But, I can't seem to figure out how to create a relationship between the nodes according to the numeric property for process number.

Any help would be much appreciated :slightly_smiling_face:

MATCH (p:Stage)
WITH p order by p.id
RETURN p

Thanks Ameyasoft. That seems to give me a whole load more nodes, but still no relationship between the nodes.

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?

From your LOAD CSV, I didn't see any relationships. I see only node creation.

If you have any relationships between the nodes, then use this:

MATCH (p:Stage)
WITH p order by p.id
MATCH (p)-[:ABC]-(a)
RETURN p, a

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

It tells me:

And if i try to put the WITH's before match it tells me:

Let me know about your Neo4j version and is community/desktop/enterprise?

I have normal desktop

Sorry I meant Neo4j Desktop version

Yes, it's the desktop Neo4j that i have

Did you install APOC?

No, i haven't, should I add it in? I haven't added any extensions so far

I have Neo4j 1.2.8, would [apoc-4.3.0-rc01-all.jar] be the right one to get?

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 :slightly_smiling_face: . 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')

You have to get the APOC to match the version of Neo4J. Neo4J 1.2.8 is positively ancient. You should upgrade to the latest 4.2.1.

(added) Oops. My misunderstanding. 1.2.8 must be the version of the desk top. Nevermind.

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:

...and when I try to open the database, it tells me this:

If I select 'Fix Configuration' it basically just does the same again. :confused:

I mean, basically it tells me this after I 'Fix configuration':

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