Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find path between nodes through cypher

Tags:

neo4j

cypher

I created a application the fills a Neo4J database with emails records. I created 2 types of nodes, person & mail and I created 4 types of relationships, sent, cc, to & reply_of.

Now I want to find relationships between 2 nodes that aren't directly connected. For example between P1 & P3 (see picture).

How can I achieve this through cypher? Is it doable in neo4j?

Relationship between persons & mails

Updated question:

First let me clear something about the picture...

The Reply_OF relationship is a relationship between mail nodes. It creates a relationship between the original mail and any reply of forward mail. The Sent, To, Cc & Bcc relationships create relations between a person node and a mail node. There is no direct relation between person nodes.

Submitting this question and reading the answers made me realise I wanted to know something else...what I really would like to know is how can I show all person nodes that have seen a reply or forward mail from the original mail that where not on the To, Cc or Bcc lists in the original mail.

like image 739
Martijn Avatar asked Dec 20 '13 13:12

Martijn


People also ask

How do you create a relationship between two nodes in Neo4j?

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.

How do you represent a node in Cypher?

Node or Relationship Properties To represent these in Cypher, we can use curly braces within the parentheses of a node or the brackets of a relationship. The name and value of the property then go inside the curly braces. Our example graph has both a node property ( name ) and a relationship property ( since ).

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.

What does match do in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting data into the current set of bindings. It is worth reading up more on the specification of the patterns themselves in Patterns.


1 Answers

Answer to the updated question:

I assume your email nodes carry a label of Email and have a property mailId.

MATCH (mailToTrack:Email {mailId: 'mymailid'})-[:Reply_Of*1..100]->()-[:TO|:CC|:BCC]->(person)
RETURN distinct person
like image 177
Stefan Armbruster Avatar answered Oct 31 '22 12:10

Stefan Armbruster