cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Concatenate Chain of nodes

I am quite amateur using Neo4j, and I am not sure if the following doubt can be possible or not.

I am importing data from a csv in which I have different messages as follows:
From;To;Tel_from;Tel_to;
Marc;Louis;454423;86849349;
Marta;Mickel;1343;33544;
Ivan;Peter;395934;12322;
Roman;Louis;3434;142342;
Sally;Tom;2323;11111;
Tom;Peter;12342;134323;
Marc;Ivan;4545;2433; (etc etc)

What I want is to see all connections as a neural network so at the end I will see:
(LOUIS) <== (Roman)
^
||
(Marc)==>(Ivan)==>(Peter)<==(Tom)<==(Sally)

and so on (hope that the example is well enough ).

The point is that I do not really know which is the best strategy.
I do not know if with just two labels (from and to) I can get this graph.
For the moment, I am only able to make pairs of connections. However, it's not what I want.

Any idea will be more than welcome.
Thanks in advance!!!

3 REPLIES 3

Yes, you can absolutely chain nodes together like this. Check out the LOAD CSV documentation for how to load the CSV and set the field separator to semicolon and so on. But the basic pattern you'll use will be something like this:

MERGE (p1:Person { name: line.From, telephone: Tel_from })
MERGE (p2:Person { name: line.To, telephone: Tel_to })
MERGE (p1)-[:CALLED]->(p2)

But shouldn't I first load de csv or no?

Here I show you my code:
Here I create my first label (the person calling)

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///phoneCalls.csv' AS c FIELDTERMINATOR ';'
CREATE (e:sender {fecinter:c.fecinter, from:c.from, to:c.to, tel_from:c.tel_from})

Then I create the second label (the person that recieves the call)

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///phoneCalls.csv' AS c FIELDTERMINATOR ';'
CREATE (e:reciv {fecinter:c.fecinter,from:c.from, to:c.to, tel_from:c.tel_from})

So at the end what I have duplicated all the data. I do not know if this makes sense. The point is that then, when I make my relationship I get pairs of nodes, but just two, and I want to have all of them connected.

MATCH (n:sender), (b:reciv)
WHERE n.from= b.from and n.to=b.to
MERGE (n)-[:a]->(b)

I would like sometin like this
2X_1_1970ff10f01a4b12f0c7c8bbdb890d43cd22f4a1.png

Hi @joseluisjordanagomez,

Have a look at the MERGE Clause on Cypher.

You can do something like

MERGE(from:Person  { name: 'Sally' })
MERGE(to:Person {name: 'Tom'})
CREATE (from)-[:Tel {from: 2323, to: 11111}]->(to)
RETURN from, to

for every line in the csv.

The labels and how you want to store the Tel_from and Tel_to could be different depending on how you would like to use this database later on. If you just want to see the connections, this schema should suffice.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online